From baa3eccfe352f5cd1fd7bb205c5116c413fcddb9 Mon Sep 17 00:00:00 2001 From: Maps Date: Mon, 14 Apr 2025 09:06:30 +0200 Subject: [PATCH] updated analysis stuff --- scripts/cpp/analysis.cxx | 944 +++++++++++++++++++++-- scripts/cpp/analysis.hpp | 33 +- scripts/modules/Analysis/Analysis.xs | 60 +- scripts/modules/Analysis/lib/Analysis.pm | 47 +- 4 files changed, 994 insertions(+), 90 deletions(-) diff --git a/scripts/cpp/analysis.cxx b/scripts/cpp/analysis.cxx index 3efe099..f3d23f1 100644 --- a/scripts/cpp/analysis.cxx +++ b/scripts/cpp/analysis.cxx @@ -11,6 +11,9 @@ #include "TMath.h" #include "TString.h" #include "TGraph.h" +#include "TGraphErrors.h" +#include "TMultiGraph.h" +#include "TLegend.h" #include "TH1D.h" #include "TH1I.h" #include "TH2I.h" @@ -18,6 +21,8 @@ #include "TFile.h" #include "TText.h" #include "TCanvas.h" +#include "TColor.h" +#include "TStyle.h" #include "analysis.hpp" @@ -26,6 +31,10 @@ #include "hadaq/api.h" +#ifndef SLEEPVAL +#define SLEEPVAL 1000 +#endif + // TH1I* split(std::string text, char delim, int stepsize, int start, int end) { // using namespace std; @@ -106,6 +115,112 @@ Int_t GetBadY(std::string text, char delim) { } } +float GetBBV(std::string text, char delim) { + + using namespace std; + + string line; + + stringstream ss(text); + Int_t counter = 0; + while(getline(ss, line, delim)) { + TString lline (line); + if (counter == 0){ + //cout << lline << endl; + return lline.Atof(); + + } + counter++; + } +} + +float GetBBI(std::string text, char delim) { + + using namespace std; + + string line; + + stringstream ss(text); + Int_t counter = 0; + while(getline(ss, line, delim)) { + TString lline (line); + if (counter == 1){ + //cout << lline << endl; + return lline.Atof(); + + } + counter++; + } +} + +char FindMatrix(std::string text) { + + using namespace std; + + char c = text[5]; + return c; +} + +Int_t GetVCASN(std::string text, char delim) { + + using namespace std; + + string line; + + stringstream ss(text); + Int_t counter = 0; + while(getline(ss, line, delim)) { + TString lline (line); + if (counter == 0){ + //cout << lline << endl; + string sline(lline.Data()); + string rsline = sline.substr(sline.find('-') + 1); + TString rline(rsline); + return rline.Atoi(); + + } + counter++; + } +} + +float GetThresh(std::string text, char delim) { + + using namespace std; + + string line; + + stringstream ss(text); + Int_t counter = 0; + while(getline(ss, line, delim)) { + TString lline (line); + if (counter == 1){ + //cout << lline << endl; + return lline.Atof(); + + } + counter++; + } +} + +float GetFPN(std::string text, char delim) { + + using namespace std; + + string line; + + stringstream ss(text); + Int_t counter = 0; + while(getline(ss, line, delim)) { + TString lline (line); + if (counter == 2){ + //cout << lline << endl; + return lline.Atof(); + + } + counter++; + } +} + void @@ -248,7 +363,7 @@ make_fit( // // } -void +const char* analysis:: make_quick_fit( char* file, @@ -264,7 +379,7 @@ using namespace std; vector v_x(255/stepsize); // Make x axis for hists TH1D* Fpn = new TH1D("FPNHist", "FPNHist", 255, 0, 255); - TH1D* ThN = new TH1D("ThermNoiseHist", "ThermNoiseHist", 40, 0, 20); + TH1D* ThN = new TH1D("ThermNoiseHist", "ThermNoiseHist", 70, 0, 35); cout << "Reading data from CSV..." << endl; @@ -284,7 +399,7 @@ using namespace std; float minThrLimit = 20; float maxThrLimit = 230; float minNoiseLim = 0.5; - float maxNoiseLim = 20; + float maxNoiseLim = 35; ofstream outfile("BadFittedPixels.txt"); @@ -334,7 +449,7 @@ using namespace std; cout << "Fitting Threshold and Noise Histograms." << endl; TCanvas *t1 = new TCanvas(); - TF1 *gausThn = new TF1("gausThn", "gaus", 1, 20); + TF1 *gausThn = new TF1("gausThn", "gaus", 0.5, 35); TF1 *gausFpn = new TF1("gausFpn", "gaus", 30, 255); gausFpn->SetParameter(1, Fpn->GetMean(1)); gausFpn->SetParameter(2, Fpn->GetStdDev(1)); @@ -369,6 +484,14 @@ using namespace std; t->WriteObject(Fpn, "FPN"); t->WriteObject(ThN, "THN"); t->Close(); + + string* retStr = new string(to_string(gausFpn->GetParameter(1) * slopex + offset) + "\t" + to_string(gausFpn->GetParameter(2) * slopex) + "\t" + to_string(gausThn->GetParameter(1) * slopex) + "\t" + to_string(badFit)); + // //sretStr &= to_string(gausFpn->GetParameter(1) * slopex + offset) + "\t" + to_string(gausFpn->GetParameter(2) * slopex) + "\t" + to_string(gausThn->GetParameter(1) * slopex) + "\t" + to_string(badFit); + + const char* retChars = retStr->c_str(); + + return retChars; + } @@ -639,8 +762,8 @@ pixel_dump( TFile* t = new TFile("PixelMatrix.root", "recreate"); t->WriteObject(PixelMatrix, "PixelMatrix"); t->Close(); - TCanvas *t2 = new TCanvas(); + gStyle->SetPalette(kDeepSea); PixelMatrix->Draw(); t2->SaveAs("NoiseHist.png","png"); @@ -662,6 +785,7 @@ find_noisy_pixels( TH2I* PixelMatrix = nullptr; inputFile.GetObject("PixelMatrix",PixelMatrix); string noisyPix = "x-coordinate\ty-coordinate\tRate\n"; + TH2I* NoiseMatrix = new TH2I("NoiseMatrix", "NoiseMatrix", 1024, 0, 1023, 504, 0, 503); for (Int_t x = 0; x < 1024; ++x) { @@ -670,6 +794,7 @@ find_noisy_pixels( if (PixelMatrix->GetBinContent(PixelMatrix->GetBin(x,y)) >= frameLimit * noiseLimit) { noisyPix.append(to_string(x) + "\t" + to_string(y) + "\t" + to_string((PixelMatrix->GetBinContent(PixelMatrix->GetBin(x,y)) + 0.) / frameLimit) + "\n"); + NoiseMatrix->Fill(x,y); } @@ -680,6 +805,138 @@ find_noisy_pixels( ofstream outfile("noisyPixels.txt"); outfile << noisyPix; outfile.close(); + TCanvas *t2 = new TCanvas(); + NoiseMatrix->SetMaximum(2); + gStyle->SetPalette(kDeepSea); + NoiseMatrix->Draw(); + + t2->SaveAs("NoisyPixels.png", "png"); + +} + +void +analysis:: +plot_bb( char* file ) +{ + using namespace std; + + ifstream ifs(file); + + string line; + Int_t linecounter = 0; + + TGraph* gr = new TGraph(); + + while (getline(ifs, line)) { + + if (linecounter > 0) { + + gr->AddPoint(GetBBV(line, '\t'), 1000. * GetBBI(line, '\t')); + + } + + ++linecounter; + + } + + gr->SetTitle("Backbias V/I Plot;Back Bias (V);Current (mA)"); + + TCanvas *t2 = new TCanvas(); + gr->SetMarkerStyle(21); + gr->Draw(); + + t2->SaveAs("BB.png", "png"); + +} + +void +analysis:: +plot_thresh_fpn( char* file) +{ + using namespace std; + + ifstream ifs(file); + + string line; + Int_t linecounter = 0; + + TGraphErrors* grA = new TGraphErrors(); + TGraphErrors* grB = new TGraphErrors(); + TGraphErrors* grC = new TGraphErrors(); + TGraphErrors* grD = new TGraphErrors(); + + grA->SetMarkerStyle(21); + grB->SetMarkerStyle(21); + grC->SetMarkerStyle(21); + grD->SetMarkerStyle(21); + + grA->SetMarkerColor(2); + grB->SetMarkerColor(3); + grC->SetMarkerColor(4); + grD->SetMarkerColor(6); + + + + grA->SetLineColor(2); + grB->SetLineColor(3); + grC->SetLineColor(4); + grD->SetLineColor(6); + + Int_t a = 0; + Int_t b = 0; + Int_t c = 0; + Int_t d = 0; + + while (getline(ifs, line)) { + + if (linecounter > 1) { + + if (FindMatrix(line) == 'A') { + grA->AddPoint(GetVCASN(line, '\t'), GetThresh(line, '\t')); + grA->SetPointError(a, 0, GetFPN(line, '\t')); + ++a; + } + if (FindMatrix(line) == 'B') { + grB->AddPoint(GetVCASN(line, '\t'), GetThresh(line, '\t')); + grB->SetPointError(b, 0, GetFPN(line, '\t')); + ++b; + } + if (FindMatrix(line) == 'C') { + grC->AddPoint(GetVCASN(line, '\t'), GetThresh(line, '\t')); + grC->SetPointError(c, 0, GetFPN(line, '\t')); + ++c; + } + if (FindMatrix(line) == 'D') { + grD->AddPoint(GetVCASN(line, '\t'), GetThresh(line, '\t')); + grD->SetPointError(d, 0, GetFPN(line, '\t')); + ++d; + } + + } + + ++linecounter; + + } + + + TMultiGraph* mg = new TMultiGraph(); + mg->SetTitle("VCASN/Threshold and FPN plot;VCASN (LSB);Threshold and FPN (mV/e)"); + mg->Add(grA); + mg->Add(grB); + mg->Add(grC); + mg->Add(grD); + + TCanvas *t2 = new TCanvas(); + mg->Draw("ALP"); + + TLegend* legend = new TLegend(0.1,0.7,0.48,0.9); + legend->SetHeader("Legend","C"); // option "C" allows to center the header + legend->AddEntry(grA,"Matrix A","ep"); + legend->AddEntry(grB,"Matrix B","ep"); + legend->AddEntry(grC,"Matrix C","ep"); + legend->AddEntry(grD,"Matrix D","ep"); + legend->Draw(); + t2->SaveAs("VCASN.png", "png"); } @@ -692,7 +949,7 @@ plot_dead_pixels( char* matD ) { using namespace std; - TH2I* PixelMatrix = new TH2I("PixelMatrix", "PixelMatrix", 1024, 0, 1023, 504, 0, 503); + TH2I* PixelMatrix = new TH2I("DeadPixelMatrix", "DeadPixelMatrix", 1024, 0, 1023, 504, 0, 503); ifstream ifsA(matA); string lineA; @@ -771,78 +1028,198 @@ plot_dead_pixels( } TCanvas *t2 = new TCanvas(); + PixelMatrix->SetMaximum(2); + gStyle->SetPalette(kDeepSea); PixelMatrix->Draw(); - t2->SaveAs("DeadPixels.png", "png"); } - -int +void analysis:: -find_rough_threshold( - int fpga, - bool singleaccess, - int threshElectron, - int lowerLimitVCASN, - int higherLimitVCASN, - int VCASNStepSize, - int numberOfFrames, - char* matrix) -{ +plot_ineff_pixels( + char* matA, + char* matB, + char* matC, + char* matD +) { using namespace std; + TH2I* PixelMatrix = new TH2I("IneffPixelMatrix", "IneffPixelMatrix", 1024, 0, 1023, 504, 0, 503); + + ifstream ifsA(matA); + string lineA; - mimosis::register_write_sec(fpga, 0x46, threshElectron, singleaccess); - - if (matrix == "A") { + while (getline(ifsA, lineA)) { - mimosis::register_write_sec(fpga, 0x49, 1, singleaccess); - mimosis::register_write_sec(fpga, 0x4A, 1, singleaccess); - mimosis::register_write_sec(fpga, 0x4B, 1, singleaccess); + stringstream ss(lineA); + Int_t counter = 0; + Int_t x; + Int_t y; + while(getline(ss, lineA, '\t')) { + TString llineA (lineA); + if (counter == 0) {x = llineA.Atoi();} + if (counter == 1) {y = llineA.Atoi();} + ++counter; + } + PixelMatrix->Fill(x, y); } - else if (matrix == "B") { + ifstream ifsB(matB); + string lineB; + + while (getline(ifsB, lineB)) { - mimosis::register_write_sec(fpga, 0x48, 1, singleaccess); - mimosis::register_write_sec(fpga, 0x4A, 1, singleaccess); - mimosis::register_write_sec(fpga, 0x4B, 1, singleaccess); + stringstream ss(lineB); + Int_t counter = 0; + Int_t x; + Int_t y; + while(getline(ss, lineB, '\t')) { + TString llineB (lineB); + if (counter == 0) {x = llineB.Atoi();} + if (counter == 1) {y = llineB.Atoi();} + ++counter; + } + PixelMatrix->Fill(x, y); } - else if (matrix == "C") { + ifstream ifsC(matC); + string lineC; + + while (getline(ifsC, lineC)) { - mimosis::register_write_sec(fpga, 0x48, 1, singleaccess); - mimosis::register_write_sec(fpga, 0x49, 1, singleaccess); - mimosis::register_write_sec(fpga, 0x4B, 1, singleaccess); + stringstream ss(lineC); + Int_t counter = 0; + Int_t x; + Int_t y; + while(getline(ss, lineC, '\t')) { + TString llineC (lineC); + if (counter == 0) {x = llineC.Atoi();} + if (counter == 1) {y = llineC.Atoi();} + ++counter; + } + PixelMatrix->Fill(x, y); } - else if (matrix == "D") { + ifstream ifsD(matD); + string lineD; + + while (getline(ifsD, lineD)) { - mimosis::register_write_sec(fpga, 0x48, 1, singleaccess); - mimosis::register_write_sec(fpga, 0x49, 1, singleaccess); - mimosis::register_write_sec(fpga, 0x4A, 1, singleaccess); + stringstream ss(lineD); + Int_t counter = 0; + Int_t x; + Int_t y; + while(getline(ss, lineD, '\t')) { + TString llineD (lineD); + if (counter == 0) {x = llineD.Atoi();} + if (counter == 1) {y = llineD.Atoi();} + ++counter; + } + PixelMatrix->Fill(x, y); } - else {return -1;} + TCanvas *t2 = new TCanvas(); + PixelMatrix->SetMaximum(2); + gStyle->SetPalette(kDeepSea); + PixelMatrix->Draw(); + t2->SaveAs("IneffPixels.png", "png"); + - vector time (((higherLimitVCASN - lowerLimitVCASN) / VCASNStepSize) + 1); +} + + +// int +// analysis:: +// find_rough_threshold( +// char* source, +// int fpga = 0xc200, +// bool singleaccess = false, +// int threshElectron = 120, +// float precision = 0.1, +// int lowerLimitVCASN = 50, +// int higherLimitVCASN = 210, +// int VCASNStepSize = 2, +// int numberOfFrames = 500, +// int matrix = 1, +// int xLow = 0, +// int xHigh = 127, +// int yLow = 250, +// int yHigh = 251, +// int mod = 2, +// int exp = 3) +// { +// using namespace std; // -// for (int iter = 0; iter <= (((higherLimitVCASN - lowerLimitVCASN) / VCASNStepSize) + 1); ++iter) { -// -// if (matrix == "A") {register_write_sec(fpga, 0x48, (lowerLimitVCASN + iter * VCASNStepSize), singleaccess);} -// if (matrix == "B") {register_write_sec(fpga, 0x49, (lowerLimitVCASN + iter * VCASNStepSize), singleaccess);} -// if (matrix == "C") {register_write_sec(fpga, 0x4A, (lowerLimitVCASN + iter * VCASNStepSize), singleaccess);} -// if (matrix == "D") {register_write_sec(fpga, 0x4B, (lowerLimitVCASN + iter * VCASNStepSize), singleaccess);} +// mimosis::register_write(fpga, 0x46, threshElectron, singleaccess); +// +// int maxResponses; +// +// if (matrix == 1) { +// +// mimosis::register_write(fpga, 0x49, 1, singleaccess); +// mimosis::register_write(fpga, 0x4A, 1, singleaccess); +// mimosis::register_write(fpga, 0x4B, 1, singleaccess); +// +// maxResponses = (xHigh - xLow + 1) * (yHigh - yLow + 1) * numberOfFrames; +// +// } +// +// else if (matrix == 2) { +// +// mimosis::register_write(fpga, 0x48, 1, singleaccess); +// mimosis::register_write(fpga, 0x4A, 1, singleaccess); +// mimosis::register_write(fpga, 0x4B, 1, singleaccess); +// +// maxResponses = (xHigh - xLow + 1) * (yHigh - yLow + 1) * numberOfFrames; +// +// } +// +// else if (matrix == 3) { +// +// mimosis::register_write(fpga, 0x48, 1, singleaccess); +// mimosis::register_write(fpga, 0x49, 1, singleaccess); +// mimosis::register_write(fpga, 0x4B, 1, singleaccess); // +// maxResponses = (xHigh - xLow + 1) * (yHigh - yLow + 1) * numberOfFrames; +// +// } +// +// else if (matrix == 4) { +// +// mimosis::register_write(fpga, 0x48, 1, singleaccess); +// mimosis::register_write(fpga, 0x49, 1, singleaccess); +// mimosis::register_write(fpga, 0x4A, 1, singleaccess); +// +// maxResponses = (xHigh - xLow + 1) * (yHigh - yLow + 1) * numberOfFrames; +// +// } +// +// else {return -1;} +// +// +// for (int iter = lowerLimitVCASN; iter <= higherLimitVCASN; iter += VCASNStepSize) { +// +// if (matrix == 1) {mimosis::register_write(fpga, 0x48, (lowerLimitVCASN + iter * VCASNStepSize), singleaccess);} +// if (matrix == 2) {mimosis::register_write(fpga, 0x49, (lowerLimitVCASN + iter * VCASNStepSize), singleaccess);} +// if (matrix == 3) {mimosis::register_write(fpga, 0x4A, (lowerLimitVCASN + iter * VCASNStepSize), singleaccess);} +// if (matrix == 4) {mimosis::register_write(fpga, 0x4B, (lowerLimitVCASN + iter * VCASNStepSize), singleaccess);} +// // trb_register_write(fpga, 0x9209, iter); -// usleep(SLEEPVAL); -// auto start = high_resolution_clock::now(); +// usleep(SLEEPVAL); // +// int cntResponse = 0; // int mimTra = 0; +// +// int pulse = static_cast(std::pow(2.0,static_cast(exp))); +// +// hadaq::ReadoutHandle ref = hadaq::ReadoutHandle::Connect(source); +// if (ref.null()) return -1; +// hadaq::RawEvent *evnt = nullptr; // // while( mimTra>16,column,row,region); +// +// if(column >= xLow && +// column <= xHigh && +// row >= yLow && +// row <= yHigh && +// mimFraCnt%pulse == mod && +// mimFraCntOpt == iter) { +// +// cntResponse += 1; // -// int tmp = (data>>16) & 0xFF; -// if(tmp > 63) continue; -// region = tmp; +// // printf("%d %d %d %d %d %d\n", +// // column, column-xLow, row, row-yLow, vphfine, SUPERINDEX(column,xLow,xSpan,row,yLow,vphfine)); +// } +// +// int code = (data >> 16) & 0b111; +// +// if ( code & 0b1) { +// +// int codeTmp = 1; +// decode_pixel(((data >> 16) + (codeTmp << 6)), column, row, region); +// +// if(column >= xLow && column <= xHigh && +// row >= yLow && row <= yHigh && +// mimFraCnt%pulse == mod && +// mimFraCntOpt == iter) { // +// cntResponse += 1; +// } // } // -// if(mimTra >= maxCounts) { -// goto MAXCOUNTS; +// if ( code & 0b10) { +// +// int codeTmp = 2; +// decode_pixel(((data >> 16) + (codeTmp << 6)), column, row, region); +// +// if(column >= xLow && column <= xHigh && +// row >= yLow && row <= yHigh && +// mimFraCnt%pulse == mod && +// mimFraCntOpt == iter) { +// +// cntResponse += 1; +// } +// } +// +// if ( code & 0b100) { +// +// int codeTmp = 3; +// decode_pixel(((data >> 16) + (codeTmp << 6)), column, row, region); +// +// if(column >= xLow && column <= xHigh && +// row >= yLow && row <= yHigh && +// mimFraCnt%pulse == mod && +// mimFraCntOpt == iter) { +// +// cntResponse += 1; +// } +// } // } -// } // End loop over data in sub event +// +// if((data & 0x0000FF00) != 0x0000FC00) { +// +// decode_pixel(data&0xFFFF,column,row,region); +// +// if(column >= xLow && +// column <= xHigh && +// row >= yLow && +// row <= yHigh && +// mimFraCnt%pulse == mod && +// mimFraCntOpt == threshElectron) { +// +// cntResponse += 1; +// +// // printf("%d %d %d %d %d %d\n", +// // column, column-xLow, row, row-yLow, vphfine, SUPERINDEX(column,xLow,xSpan,row,yLow,vphfine)); +// } +// +// int code = (data & 0xFFFF) & 0b111; +// +// if ( code & 0b1) { +// +// int codeTmp = 1; +// decode_pixel(((data & 0xFFFF) + (codeTmp << 6)), column, row, region); +// +// if(column >= xLow && column <= xHigh && +// row >= yLow && row <= yHigh && +// mimFraCnt%pulse == mod && +// mimFraCntOpt == iter) { +// +// cntResponse += 1; +// } +// } +// +// if ( code & 0b10) { +// +// int codeTmp = 2; +// decode_pixel(((data & 0xFFFF) + (codeTmp << 6)), column, row, region); +// +// if(column >= xLow && column <= xHigh && +// row >= yLow && row <= yHigh && +// mimFraCnt%pulse == mod && +// mimFraCntOpt == iter) { +// +// cntResponse += 1; +// } +// } +// +// if ( code & 0b100) { +// +// int codeTmp = 3; +// decode_pixel(((data & 0xFFFF) + (codeTmp << 6)), column, row, region); +// +// if(column >= xLow && column <= xHigh && +// row >= yLow && row <= yHigh && +// mimFraCnt%pulse == mod && +// mimFraCntOpt == iter) { +// +// cntResponse += 1; +// } +// } +// } +// } // } // } // End loop over sub-events in event // } // MAXCOUNTS: -// auto stop = high_resolution_clock::now(); // trb_register_write(fpga, 0x9209, 0xaaaaaaaa); -// } -// -// time[iter] = duration_cast(stop-start); -// -// } -// -// double timeDiff = time[((higherLimitVCASN - lowerLimitVCASN) / VCASNStepSize) + 1] - time[0]; -// -// if (timeDiff <= 500) {return -1;} -// -// else { -// -// int lowestVCASN; -// double timediff = numeric_limits::max(); -// -// for (int iter = 0; iter <= ((higherLimitVCASN - lowerLimitVCASN) / VCASNStepSize) + 1; ++iter) { -// -// if (abs(time[iter] - timeDiff) < timediff) { -// -// lowestVCASN = lowerLimitVCASN + iter * VCASNStepSize; -// timediff = abs(time[iter] - timeDiff); -// -// } +// if ( (cntResponse + 0.) / maxResponses >= 0.5 - 0.5 * precision || (cntResponse + 0.) / maxResponses <= 0.5 + 0.5 * precision ) {return iter;} // // } -// -// return lowestVCASN; -// -// } +// +// return -2; +// +// } +void +analysis:: +try_write_sec() { + using namespace std; + + mimosis::register_write_sec(0xc200, 0x46, 120, false); + } + +int +analysis:: +find_rough_threshold( + char* source, + int fpga = 0xc200, + bool singleaccess = false, + int threshElectron = 120, + float precision = 0.1, + int lowerLimitVCASN = 50, + int higherLimitVCASN = 210, + int VCASNStepSize = 2, + int numberOfFrames = 500, + int matrix = 1, + int xLow = 0, + int xHigh = 127, + int yLow = 250, + int yHigh = 251, + int mod = 2, + int exp = 3) +{ + using namespace std; + + mimosis::register_write_sec(fpga, 0x46, threshElectron, singleaccess); + + float maxResponses; + + if (matrix == 1) { + + mimosis::register_write_sec(fpga, 0x49, 1, singleaccess); + mimosis::register_write_sec(fpga, 0x4A, 1, singleaccess); + mimosis::register_write_sec(fpga, 0x4B, 1, singleaccess); + + maxResponses = (xHigh - xLow + 1) * (yHigh - yLow + 1) * numberOfFrames; + + } + + else if (matrix == 2) { + + mimosis::register_write_sec(fpga, 0x48, 1, singleaccess); + mimosis::register_write_sec(fpga, 0x4A, 1, singleaccess); + mimosis::register_write_sec(fpga, 0x4B, 1, singleaccess); + + maxResponses = (xHigh - xLow + 1) * (yHigh - yLow + 1) * numberOfFrames; + + } + + else if (matrix == 3) { + + mimosis::register_write_sec(fpga, 0x48, 1, singleaccess); + mimosis::register_write_sec(fpga, 0x49, 1, singleaccess); + mimosis::register_write_sec(fpga, 0x4B, 1, singleaccess); + + maxResponses = (xHigh - xLow + 1) * (yHigh - yLow + 1) * numberOfFrames; + + } + + else if (matrix == 4) { + + mimosis::register_write_sec(fpga, 0x48, 1, singleaccess); + mimosis::register_write_sec(fpga, 0x49, 1, singleaccess); + mimosis::register_write_sec(fpga, 0x4A, 1, singleaccess); + + maxResponses = (xHigh - xLow + 1) * (yHigh - yLow + 1) * numberOfFrames; + + } + + else {return -1;} + + + for (int iter = lowerLimitVCASN; iter <= higherLimitVCASN; iter += VCASNStepSize) { + + if (matrix == 1) {mimosis::register_write_sec(fpga, 0x48, (iter), singleaccess);} + if (matrix == 2) {mimosis::register_write_sec(fpga, 0x49, (iter), singleaccess);} + if (matrix == 3) {mimosis::register_write_sec(fpga, 0x4A, (iter), singleaccess);} + if (matrix == 4) {mimosis::register_write_sec(fpga, 0x4B, (iter), singleaccess);} + + trb_register_write(fpga, 0x9209, iter); + usleep(SLEEPVAL); + + int cntResponse = 0; + int mimTra = 0; + + int pulse = static_cast(std::pow(2.0,static_cast(exp))); + + hadaq::ReadoutHandle ref = hadaq::ReadoutHandle::Connect(source); + if (ref.null()) return -1; + hadaq::RawEvent *evnt = nullptr; + + while( mimTraNextSubevent(sub)) != nullptr) && (sub->GetId() == fpga)) // Does not work!! + while ((sub = evnt->NextSubevent(sub)) != nullptr) + { + if (sub->GetId() == fpga) + { + unsigned size = sub->GetNrOfDataWords(); + + int headerNow = 0; + + uint32_t mimFraCnt; + uint32_t mimFraCntOpt; + + unsigned region = 0, column = 0, row = 0; + + for( unsigned i = 0; i(sub->Data(i)); + + if((data & 0xFF000000) == 0xFE000000) { + + ++headerNow; + + if(headerNow == 1) { + + mimFraCnt = (data & 0xFF0000) >> 16; + mimFraCnt += (data & 0xFF) << 8; + + } else if(headerNow == 2) { + + mimFraCnt += data & 0xFF0000; + mimFraCnt += (data & 0xFF) << 24; + + // std::printf("%x\n",mimFraCnt); + + } else if(headerNow == 3) { + mimFraCntOpt = (data & 0xFF0000) >> 16; + mimFraCntOpt += (data & 0xFF) << 8; + } else if(headerNow == 4) { + mimFraCntOpt += data & 0xFF0000; + mimFraCntOpt += (data & 0xFF) << 24; + } + + } else if((data & 0xFF000000) == 0xFF000000) { + + headerNow = 0; + if(mimFraCnt%pulse == mod && + mimFraCntOpt == iter) { mimTra++;} + // cout << "Next counter" << endl;} + + } + + + + else { + + if( (data & 0xFF000000) == 0xFD000000 ) { + + int tmp = (data>>16) & 0xFF; + if(tmp > 63) continue; + region = tmp; + + } else { + + decode_pixel(data>>16,column,row,region); + + // cout << column << " " << row << " " << region << endl; + + if(column >= xLow && + column <= xHigh && + row >= yLow && + row <= yHigh && + mimFraCnt%pulse == mod && + mimFraCntOpt == iter) { + + cntResponse += 1; + + // printf("%d %d %d %d %d %d\n", + // column, column-xLow, row, row-yLow, vphfine, SUPERINDEX(column,xLow,xSpan,row,yLow,vphfine)); + } + + int code = (data >> 16) & 0b111; + + if ( code & 0b1) { + + int codeTmp = 1; + decode_pixel(((data >> 16) + (codeTmp << 6)), column, row, region); + + if(column >= xLow && column <= xHigh && + row >= yLow && row <= yHigh && + mimFraCnt%pulse == mod && + mimFraCntOpt == iter) { + + cntResponse += 1; + } + } + + if ( code & 0b10) { + + int codeTmp = 2; + decode_pixel(((data >> 16) + (codeTmp << 6)), column, row, region); + + if(column >= xLow && column <= xHigh && + row >= yLow && row <= yHigh && + mimFraCnt%pulse == mod && + mimFraCntOpt == iter) { + + cntResponse += 1; + } + } + + if ( code & 0b100) { + + int codeTmp = 3; + decode_pixel(((data >> 16) + (codeTmp << 6)), column, row, region); + + if(column >= xLow && column <= xHigh && + row >= yLow && row <= yHigh && + mimFraCnt%pulse == mod && + mimFraCntOpt == iter) { + + cntResponse += 1; + } + } + }} + + if((data & 0x0000FF00) != 0x0000FC00) { + + decode_pixel(data&0xFFFF,column,row,region); + + if(column >= xLow && + column <= xHigh && + row >= yLow && + row <= yHigh && + mimFraCnt%pulse == mod && + mimFraCntOpt == iter) { + + cntResponse += 1; + + // printf("%d %d %d %d %d %d\n", + // column, column-xLow, row, row-yLow, vphfine, SUPERINDEX(column,xLow,xSpan,row,yLow,vphfine)); + } + + int code = (data & 0xFFFF) & 0b111; + + if ( code & 0b1) { + + int codeTmp = 1; + decode_pixel(((data & 0xFFFF) + (codeTmp << 6)), column, row, region); + + if(column >= xLow && column <= xHigh && + row >= yLow && row <= yHigh && + mimFraCnt%pulse == mod && + mimFraCntOpt == iter) { + + cntResponse += 1; + } + } + + if ( code & 0b10) { + + int codeTmp = 2; + decode_pixel(((data & 0xFFFF) + (codeTmp << 6)), column, row, region); + + if(column >= xLow && column <= xHigh && + row >= yLow && row <= yHigh && + mimFraCnt%pulse == mod && + mimFraCntOpt == iter) { + + cntResponse += 1; + } + } + + if ( code & 0b100) { + + int codeTmp = 3; + decode_pixel(((data & 0xFFFF) + (codeTmp << 6)), column, row, region); + + if(column >= xLow && column <= xHigh && + row >= yLow && row <= yHigh && + mimFraCnt%pulse == mod && + mimFraCntOpt == iter) { + + cntResponse += 1; + } + } + } + + + } + }// if(mimTra >= numberOfFrames) { + // goto MAXCOUNTS; + // } + } // End loop over sub-events in event + } + //MAXCOUNTS: + ref.Disconnect(); + trb_register_write(fpga, 0x9209, 0xaaaaaaaa);/* + cout << "Trying out VCASN " << iter << "Response Counter " << cntResponse << "Response Rate " << (cntResponse + 0.)/ maxResponses << endl;*/ + std::printf("Trying out VCASN: %3d, Response Counter: %3d, Response Rate: %3f\r",iter, cntResponse, (cntResponse + 0.)/ maxResponses); + fflush(stdout); + if ( (((cntResponse + 0.) / maxResponses) >= (0.5 - 0.5 * precision)) && (((cntResponse + 0.) / maxResponses) <= (0.5 + 0.5 * precision) )) { + std::printf("\n"); + return iter; + } + + } + std::printf("\n"); + + return -1; + +} + + diff --git a/scripts/cpp/analysis.hpp b/scripts/cpp/analysis.hpp index 296baaa..24211a4 100644 --- a/scripts/cpp/analysis.hpp +++ b/scripts/cpp/analysis.hpp @@ -1,6 +1,8 @@ #ifndef ANALYSIS_HPP #define ANALYSIS_HPP +#include + namespace analysis { void make_fit( @@ -10,7 +12,7 @@ namespace analysis int stepsize, int maxPulse ); - void make_quick_fit( + const char* make_quick_fit( char* file, float offset, float slopex, @@ -30,6 +32,14 @@ namespace analysis float noiseLimit ); + void plot_bb( + char* file + ); + + void plot_thresh_fpn( + char* file + ); + void plot_dead_pixels( char* matA, char* matB, @@ -37,16 +47,35 @@ namespace analysis char* matD ); + void plot_ineff_pixels( + char* matA, + char* matB, + char* matC, + char* matD + ); + int find_rough_threshold( + char* source, int fpga, bool singleaccess, int threshElectron, + float precision, int lowerLimitVCASN, int higherLimitVCASN, int VCASNStepSize, int numberOfFrames, - char* matrix + int matrix, + int xLow, + int xHigh, + int yLow, + int yHigh, + int mod, + int exp ); + + void try_write_sec(); }; + + #endif //ANALYSIS_HPP diff --git a/scripts/modules/Analysis/Analysis.xs b/scripts/modules/Analysis/Analysis.xs index b2a7207..2ff4cc9 100644 --- a/scripts/modules/Analysis/Analysis.xs +++ b/scripts/modules/Analysis/Analysis.xs @@ -15,8 +15,6 @@ extern "C" { MODULE = Analysis PACKAGE = Analysis - - void mimosis_make_fit(file,offset,slopex,stepSize,maxPulse) char* file @@ -28,8 +26,7 @@ mimosis_make_fit(file,offset,slopex,stepSize,maxPulse) analysis::make_fit(file, offset, slopex, stepSize, maxPulse); - -void +const char* mimosis_make_quick_fit(file,offset,slopex,stepSize,maxPulse,start,end) char* file float offset @@ -39,7 +36,9 @@ mimosis_make_quick_fit(file,offset,slopex,stepSize,maxPulse,start,end) int start int end CODE: - analysis::make_quick_fit(file, offset, slopex, stepSize, maxPulse, start, end); + RETVAL = analysis::make_quick_fit(file, offset, slopex, stepSize, maxPulse, start, end); + OUTPUT: + RETVAL @@ -50,7 +49,19 @@ mimosis_pixel_dump(fpga, frameLimit, src) char* src CODE: analysis::pixel_dump(fpga, frameLimit, src); + +void +mimosis_plot_bb(file) + char* file + CODE: + analysis::plot_bb(file); +void +mimosis_plot_thresh_fpn(file) + char* file + CODE: + analysis::plot_thresh_fpn(file); + void mimosis_find_noisy_pixels(file, frameLimit, noiseLimit) char* file @@ -68,3 +79,42 @@ mimosis_plot_dead_pixels(matA, matB, matC, matD) char* matD CODE: analysis::plot_dead_pixels(matA, matB, matC, matD); + +void +mimosis_plot_ineff_pixels(matA, matB, matC, matD) + char* matA + char* matB + char* matC + char* matD + CODE: + analysis::plot_ineff_pixels(matA, matB, matC, matD); + + + +int +mimosis_find_rough_threshold(source,fpga,singleaccess,threshElectron,precision,lowerLimitVCASN,higherLimitVCASN, VCASNStepSize, numberOfFrames, matrix, xLow, xHigh, yLow, yHigh, mod, exp) + char* source + int fpga + bool singleaccess + int threshElectron + float precision + int lowerLimitVCASN + int higherLimitVCASN + int VCASNStepSize + int numberOfFrames + int matrix + int xLow + int xHigh + int yLow + int yHigh + int mod + int exp + CODE: + RETVAL = analysis::find_rough_threshold(source,fpga,singleaccess,threshElectron,precision,lowerLimitVCASN,higherLimitVCASN, VCASNStepSize, numberOfFrames, matrix, xLow, xHigh, yLow, yHigh, mod, exp); + OUTPUT: + RETVAL + +void +try_write_sec() + CODE: + analysis::try_write_sec(); diff --git a/scripts/modules/Analysis/lib/Analysis.pm b/scripts/modules/Analysis/lib/Analysis.pm index c4ce83c..7a536ec 100644 --- a/scripts/modules/Analysis/lib/Analysis.pm +++ b/scripts/modules/Analysis/lib/Analysis.pm @@ -56,7 +56,7 @@ sub mimosis_make_quick_fit { $end, ) = @_; - analysis::make_quick_fit( $file, $offset, $slopex, $stepsize, $maxPulse, $start, $end ); + return newSVpv(analysis::make_quick_fit( $file, $offset, $slopex, $stepsize, $maxPulse, $start, $end ), 0); }; @@ -97,6 +97,51 @@ sub mimosis_plot_dead_pixels { }; +sub mimosis_plot_bb { + + my ( + $file + ) = @_; + + analysis::plot_bb( $file ); + +}; + +sub mimosis_plot_thresh_fpn { + + my ( + $file + ) = @_; + + analysis::plot_thresh_fpn( $file ); + +}; + +#sub mimosis_find_rough_threshold { +# +# my ( +# $source, +# $fpga, +# $singleaccess, +# $threshElectron, +# $precision, +# $lowerLimitVCASN, +# $higherLimitVCASN, +# $VCASNStepSize, +# $numberOfFrames, +# $matrix, +# $xLow, +# $xHigh, +# $yLow, +# $yHigh, +# $mod, +# $exp +# ) = @_; +# +# return analysis::find_rough_threshold( $source,$fpga,$singleaccess,$threshElectron,$precision,$lowerLimitVCASN,$higherLimitVCASN,$VCASNStepSize,$numberOfFrames,$matrix,$xLow,$xHigh,$yLow,$yHigh,$mod,$exp ); +# +#}; + # Preloaded methods go here. 1; -- 2.43.0