Skip to content

Commit

Permalink
seperated tests into seperate arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
cbetanco committed Aug 3, 2018
1 parent e6fa74e commit c50129d
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 272 deletions.
153 changes: 68 additions & 85 deletions Ana_tests.C
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ void Ana_tests::Get_run(string option, int runs, string outText) {

}

// cout << "test 0" << endl;
// vector<int> h1;


for(int i = 0; i < 128; i++) {
m_avg_adc[i] = avg_ADC[i];
//cout << "test" << endl;
m_std_dev[i] = calculateSD(ADC_runs[i], runs);
//cout << "test 2 "<< endl;

//h1 = histogram(m_hmin,m_bins,ADC_runs[i],runs);
//m_hist[i]=h1;
//h1.clear();
}

m_noise = 0;
Expand Down Expand Up @@ -221,9 +223,8 @@ bool Ana_tests::Baseline_corr() {


// check noise functionality of chip. Specify run number and data output stream type, i.e. masked ch ("MASK"), sync ch ("SYNC"), after ped sub ("PEDS"), after mcm("MCMS"), and either Normal or NZS data packet
void Ana_tests::Get_noise(int runs, string data_type, string option) {
bool Ana_tests::Get_noise(int runs, string data_type, string option) {

//option = "NZS";
string outText;
uint8_t buffer=0x00;

Expand All @@ -234,8 +235,7 @@ void Ana_tests::Get_noise(int runs, string data_type, string option) {
// DSP output
salt_->write_salt(registers::ser_source_cfg,(uint8_t) 0x20);

// loop over different data streams, i.e. masked ADC, sync ADC, after ped, after mcms

// check which data stream is selected
if(data_type == "MASK")
buffer = 0x00;
else if(data_type == "SYNC")
Expand All @@ -246,6 +246,7 @@ void Ana_tests::Get_noise(int runs, string data_type, string option) {
buffer = 0x60;
else {
cout << "ERROR:: Data stream not properly defined" << endl;
return false;
}

salt_->write_salt(registers::n_zs_cfg, buffer);
Expand All @@ -260,32 +261,78 @@ void Ana_tests::Get_noise(int runs, string data_type, string option) {
else {

cout <<"ERROR::n_zs_cfg not properly defined" << endl;
return;
return false;

}

// Do Normal packet
Get_run(option,runs,outText);

for(int i = 0; i < 128; i++) {


cout << "NOISE = " << m_noise << " +- " << m_noise_rms << endl;
salt_->write_salt(registers::n_zs_cfg, (uint8_t) 0);

//m_hmin=-10;
//m_bins=20;

adc_output();
return true;


}

void Ana_tests::adc_output() {

for(int i = 0; i < 128; i++) {

cout << showpos<< fixed << setprecision(3) << m_avg_adc[i] << "\t";

}
cout << endl;

for(int i = 0; i < 128; i++) {
}
cout << endl;

for(int i = 0; i < 128; i++) {

cout << showpos << fixed << setprecision(3) << m_std_dev[i] << "\t";

}
cout << endl;

// cout << m_hmin << endl << m_bins << endl;
// for(int i = 0; i < 128; i++) {

// for(int j = 0; j < m_bins; j++) {

// cout << setprecision(3) << m_hist[i].at(j) << "\t";

cout << showpos << fixed << setprecision(3) << m_std_dev[i] << "\t";
// }
// cout << endl;

// }
}

// make histogram
vector<int> Ana_tests::histogram(int start, int bins, int data[], int size) {

int counter = 0;
vector<int> hist;

for (int i = start; i < (start + bins); i++) {

counter = 0;

for(int j=0; j< size; j++) {

if(data[j]>=i && data[j] <i+1) counter++;

}
cout << endl;

cout << "NOISE " << data_type << ": " << m_noise << " +- " << m_noise_rms << endl;
salt_->write_salt(registers::n_zs_cfg, (uint8_t) 0);
hist.push_back(counter);

}

return hist;


}

// checks mcmch and mcm_v
Expand Down Expand Up @@ -486,7 +533,7 @@ void Ana_tests::Check_Gain() {
salt_->write_salt(registers::calib_enable0_cfg,(uint8_t) 0x0F);
salt_->write_salt(registers::calib_clk_cfg, (uint8_t) 0x20);
//Get_run("Calib",1,true,"test_pulse");
//Get_run("Calib",1,"test_pulse");
salt_->write_salt(registers::n_zs_cfg, (uint8_t) 0x60);
salt_->write_salt(registers::calib_volt_cfg, (uint8_t) 31);
Expand All @@ -510,74 +557,10 @@ void Ana_tests::Check_Gain() {
}
salt_->write_salt(registers::n_zs_cfg, (uint8_t) 0);
*/
}
*/

bool Ana_tests::Get_Quad_Coef(float x[], float y[], int PointsNum, float &a, float &b, float &c) {


const double S00=PointsNum;//points number
double S40=0, S10=0, S20=0, S30=0, S01=0, S11=0, S21 = 0;
double value = 0, indexPow2 = 0;
const double MINvalue = y[0];
const double MINtime = x[0];
int index = -1;
for (int i=0; i<PointsNum; i++ ){
index = x[i] - MINtime;
value = (y[i] - MINvalue); //normalizing
// cout << "i=" << i << " index=" << index << " value=" << value << endl;
S40+= pow(index,4);
S30+= pow(index,3);
indexPow2 = pow(index,2);
S20+= indexPow2;
S10+= index;

S01 += value;
S11 += value*index;
S21 += value*indexPow2;
}


double S20squared = pow(S20,2);
//minors M_ij=M_ji
double M11 = S20*S00;
M11 -= pow(S10,2);

double M21 = S30*S00;
M21 -= S20*S10;
double M22 = S40*S00;
M22 -= S20squared;
double M31 = S30*S10;
M31 -= S20squared;

double M32 = S40*S10;
M32 -= S20*S30;
// double M33 = S40*S20 - pow(S30,2);

double discriminant = S40*M11;
discriminant -= S30*M21;
discriminant += S20*M31;
// cout << "discriminant=" << discriminant << endl;
if (abs(discriminant) < .00000000001) return false;

double Da = S21*M11;
Da -= S11*M21;
Da += S01*M31;
a = Da/discriminant;
// cout << "discriminant=" << discriminant;
// cout << " Da=" << Da;

double Db = -S21*M21;
Db += S11*M22;
Db -= S01*M32;
b = Db/discriminant;
// cout << " Db=" << Db << endl;



//critPoint = -Db/(2*Da) + MINtime; //-b/(2*a)= -Db/discriminant / (2*(Da/discriminant)) = -Db/(2*Da);

return true;

}

Expand Down
9 changes: 8 additions & 1 deletion Ana_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Fpga.h"
#include "fastComm.h"
#include <fstream>
#include <vector>

using namespace std;

Expand All @@ -23,17 +24,23 @@ class Ana_tests {
void output_file(int runs, float avg_ADC[], float avg_chip[], float avg_noise, float length_avg, string outText, string option);
void Trim_dac_scan();
void Check_Gain();
void Get_noise(int runs, string data_type, string option);
bool Get_noise(int runs, string data_type, string option);
bool Check_NZS();
bool Baseline_corr();
float calculateSD(float data[], int runs);
float calculateSD(int data[], int runs);
void adc_output();
vector<int> histogram(int start, int bins, int data[], int size);
//vector<int> m_hist[128];
int m_hmin;
int m_bins;
float m_avg_adc[128];
float m_std_dev[128];
float m_noise;
float m_noise_rms;
int m_mcm_ch;
int m_mcm_v;
// vector<int> hist;
bool Check_PedS();
bool Check_MCMS();
bool Check_MCMS(float ADC[128], int mcm1, int mcm2, int mcm_ch, int mcm_v);
Expand Down
8 changes: 5 additions & 3 deletions Dig_Clk_test.C
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ bool Dig_Clk_test::TFC_Command_Check() {
// set synch pattern registers
salt_->write_salt(registers::sync1_cfg,(uint8_t) 0x8C);
salt_->write_salt(registers::sync0_cfg,(uint8_t) 0xAB);



// check TFC commands
string option[8];
bool pass[8] = {false};
Expand All @@ -438,16 +439,17 @@ bool Dig_Clk_test::TFC_Command_Check() {
else if(option[i] == "BxVeto") command[79] = 0x10;
else if(option[i] == "Snapshot") command[79] = 0x20;
else if(option[i] == "Synch") command[79] = 0x40;



fastComm_->Take_a_run(length_read, data_string, length, 0, command, period, singleShot, true );

for(int j=0; j<data_string.length(); j+=3) {

twelveBits = fastComm_->read_twelveBits(data_string, j);
if(twelveBits == 0x0F0) continue;
fastComm_->read_Header(twelveBits, bxid, parity, flag, length1);


if(flag == 0) {
if(option[i] == "Normal") pass[i] = true;
if(option[i] == "BXReset" && bxid == 0) pass[i] = true;
Expand Down
2 changes: 1 addition & 1 deletion Salt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Salt::Salt(int8_t bus_number,int8_t device_address) : I2C( bus_number, device_address)
{
std::cout << "SALT open bus" << std::endl;
// std::cout << "SALT open bus" << std::endl;
this->open_bus();
}
Salt::~Salt(){}
Expand Down
46 changes: 26 additions & 20 deletions fastComm.C
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,28 @@ void FastComm::read_daq(uint8_t length, uint32_t (&packet)[5120])

string FastComm::read_daq(uint8_t length)
{
uint64_t data;
stringstream data_stream;
// clock_t begin, end;// = clock();
for(uint i = 0; i < length; i++)
{
fpga_->read_fpga(registers::DAQ_READ0, &data);
// begin = clock();
data_stream << hex << arrange_Elinks(data);
// end=clock();
//packet[i]=data;

}
//double elapsed_sec = double(end - begin) / CLOCKS_PER_SEC;
// cout << "I2C time: " << elapsed_sec << " seconds" << endl;
//cout << "test data stream = " << data_stream.str() << endl;
return data_stream.str();
// arrange_Elinks(data);

uint64_t data;
stringstream data_stream;
// clock_t begin, end;// = clock();
for(uint i = 0; i < length; i++)
{

fpga_->read_fpga(registers::DAQ_READ0, &data);
// begin = clock();

data_stream << hex << arrange_Elinks(data);
// end=clock();

//packet[i]=data;

}
//double elapsed_sec = double(end - begin) / CLOCKS_PER_SEC;
// cout << "I2C time: " << elapsed_sec << " seconds" << endl;
//cout << "test data stream = " << data_stream.str() << endl;

return data_stream.str();
// arrange_Elinks(data);


}

Expand Down Expand Up @@ -288,16 +292,18 @@ void FastComm::Take_a_run(uint16_t length_read, uint32_t (&packet)[5120], uint8_
void FastComm::Take_a_run(uint16_t length_read, string &data, uint8_t length, uint8_t clock_delay, uint8_t command[], uint8_t period, bool singleShot, bool tfc_trig)
{


// string data_stream;
this->config_daq(length_read, clock_delay, tfc_trig);
//if (tfc_trig)

this->config_tfc(length, command, period, singleShot);

this->Launch_ACQ(tfc_trig);

data = this->read_daq(length_read);


//cout <<"this is a test" << endl;
//cout << "string is " << data << endl;
//read_NZS_packet(data_stream);
reset_DAQ();
Expand Down
Loading

0 comments on commit c50129d

Please sign in to comment.