Commit 9e2617f7 authored by wiederkehr_s's avatar wiederkehr_s
Browse files

Merge branch 'tilman-branch' into 'master'

Tilman branch

See merge request !2
parents fb9145a8 dda52d8b
......@@ -2,7 +2,7 @@
UNAME := $(shell uname)
#cmd_analyzer.o
OBJS = cmd.o command.o cmd_dtb.o cmd_analyzer.o error.o file.o pixel_dtb.o profiler.o protocol.o r4stest.o rpc_calls.o rpc.o rpc_error.o rpc_io.o scanner.o settings.o usb.o linux/rs232.o
OBJS = cmd.o command.o cmd_dtb.o cmd_analyzer.o error.o file.o pixel_dtb.o profiler.o protocol.o r4stest.o rpc_calls.o rpc.o rpc_error.o rpc_io.o scanner.o settings.o usb.o linux/rs232.o R4sImg.o R4sLine.o
ROOTCFLAGS = $(shell $(ROOTSYS)/bin/root-config --cflags)
# root C flags = -pthread -m64 -I/home/pitzl/ROOT/armin/root-cern/include
......
/* -------------------------------------------------------------
*
* file: R4sImg.cpp
*
* description: Converts rawdata from dtb into a "readable" Image
*
* author: Beat Meier
* modified: 31.8.2007
*
* rev: Tilman Rohe
* dat: 28.08.2017
*
* -------------------------------------------------------------
*/
#include "cmd.h"
#include "datalink.h"
#include "R4sImg.h"
//#include "pixelAlive.h"
#include "TROOT.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TString.h"
#include "TTree.h"
#include "TBranch.h"
#include "TLeaf.h"
#include "TGraph.h"
#include "TMultiGraph.h"
#include "TLegend.h"
#include "TCanvas.h"
int R4sImg::Get(int x, int y) {
if ( y>IMG_HEIGHT || x>IMG_WIDTH )
{printf("ERROR: Out of range");return -9999;}
return data[y*IMG_WIDTH + x];
}
bool R4sImg::CreateRaw(const vector<uint16_t> &rawdata)
{
Clear();
if (rawdata.size() < IMG_WIDTH*IMG_HEIGHT) return false;
data = new int[IMG_WIDTH*IMG_HEIGHT];
for (int pos=0; pos<IMG_WIDTH*IMG_HEIGHT; pos++)
{
int value = rawdata[pos];
if (value & 0x1000) // ADC overrange
value = R4S_VALUE_OR;
else if (value & 0x0800) // negative
value -= 0x1000;
data[pos] = value;
dataNEW.push_back(value);
}
return true;
};
void R4sImg::Print(unsigned int count)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
if (count > IMG_WIDTH*IMG_HEIGHT) count = IMG_WIDTH*IMG_HEIGHT;
for (unsigned int i=0; i<count; i++)
{
int v = data[i];
if (v == R4S_VALUE_OR) printf(" or"); else printf(" %4i", v);
}
printf("\n");
tb.Daq_Close();
}
void R4sImg::Save(const string &filename)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
FILE *f = fopen(filename.c_str(), "wt");
if (!f) return;
int i = 0, x, y;
for (y=IMG_HEIGHT-1; y>=0; y--)
{
for (x=0; x<IMG_WIDTH; x++)
{
int v = Get(x,y);
if (v == R4S_VALUE_OR) fprintf(f, " or"); else fprintf(f, " %4i", v);
}
fputs("\n", f);
}
fclose(f);
}
void R4sImg::Add(R4sImg &tmp){
for (int pos=0; pos<IMG_WIDTH*IMG_HEIGHT; pos++)
{
data[pos] += tmp.Get(pos);
}
return;
}
void R4sImg::Substract(R4sImg &tmp){
for (int pos=0; pos<IMG_WIDTH*IMG_HEIGHT; pos++)
{
data[pos] -= tmp.Get(pos);
}
return;
}
void R4sImg::Divide(R4sImg &tmp, int denominator){
for (int pos=0; pos<IMG_WIDTH*IMG_HEIGHT; pos++)
{
data[pos] /= denominator;
}
return;
}
#define IMG_WIDTH 157
#define IMG_HEIGHT 163
#define R4S_VALUE_OR 4096
class R4sImg
{
int *data;
int *dataSum; // sum of images
int nImgs = 1; // number of images averaged
std::vector<int> dataNEW;
public:
R4sImg() : data(0) {}
bool CreateRaw(const vector<uint16_t> &rawdata);
void Clear() { if (data) delete[] data; data = 0; }//dataNEW.clear();}
void Save(const string &filename);
void Print(unsigned int count);
int Get(int x, int y);
int Get(int pos) {return data[pos];}
void Add(R4sImg &tmp);
void Substract(R4sImg &tmp);
void Divide(R4sImg &tmp, int denominator);
std::vector<int> getData() {return dataNEW;}
};
\ No newline at end of file
/* -------------------------------------------------------------
*
* file: R4sLine.cpp
*
* description: converts rawdata of 1 pixel line from dtb to Integers
*
* author: Tilman Rohe
* modified: 29.9.2017
*
* rev:
* dat:
*
* -------------------------------------------------------------
*/
#include "cmd.h"
#include "datalink.h"
#include "R4sLine.h"
//#include "pixelAlive.h"
#include "TROOT.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TString.h"
#include "TTree.h"
#include "TBranch.h"
#include "TLeaf.h"
#include "TGraph.h"
#include "TMultiGraph.h"
#include "TLegend.h"
#include "TCanvas.h"
int R4sLine::Get(int x) {
if (x>IMG_WIDTH )
{printf("ERROR: Out of range");return -9999;}
return data[x];
}
bool R4sLine::CreateRaw(const vector<uint16_t> &rawdata)
{
Clear();
if (rawdata.size() < IMG_WIDTH) return false;
data = new int[IMG_WIDTH];
for (int pos=0; pos<IMG_WIDTH; pos++)
{
int value = rawdata[pos];
if (value & 0x1000) // ADC overrange
value = R4S_VALUE_OR;
else if (value & 0x0800) // negative
value -= 0x1000;
data[pos] = value;
//dataNEW.push_back(value);
}
return true;
};
void R4sLine::Print(unsigned int count)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
if (count > IMG_WIDTH) count = IMG_WIDTH;
for (unsigned int i=0; i<count; i++)
{
int v = data[i];
if (v == R4S_VALUE_OR) printf(" or"); else printf(" %4i", v);
}
printf("\n");
//tb.Daq_Close();
}
void R4sLine::Save(const string &filename)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
FILE *f = fopen(filename.c_str(), "wt");
if (!f) return;
int i = 0, x;
for (x=0; x<IMG_WIDTH; x++)
{
int v = Get(x);
if (v == R4S_VALUE_OR) fprintf(f, " or"); else fprintf(f, " %4i", v);
}
fputs("\n", f);
fclose(f);
}
#define IMG_WIDTH 157
#define IMG_HEIGHT 163
#define R4S_VALUE_OR 4096
class R4sLine
{
int *data;
//std::vector<int> dataNEW;
public:
R4sLine() : data(0) {}
bool CreateRaw(const vector<uint16_t> &rawdata);
void Clear() { if (data) delete[] data; data = 0; }//dataNEW.clear();}
void Save(const string &filename);
void Print(unsigned int count);
int Get(int x);
//std::vector<int> getData() {return dataNEW;}
};
......@@ -7,7 +7,8 @@
* author: Beat Meier
* modified: 31.8.2007
*
* rev:
* rev: Tilman Rohe
* dat: 22.08.2017
*
* -------------------------------------------------------------
*/
......@@ -15,105 +16,64 @@
#include "cmd.h"
#include "datalink.h"
#include "R4sImg.h"
#include "R4sLine.h"
#define IMG_WIDTH 157
#define IMG_HEIGHT 163
#define R4S_VALUE_OR 4096
class R4sImg
{
int *data;
std::vector<int> dataNEW;
public:
R4sImg() : data(0) {}
bool CreateRaw(const vector<uint16_t> &rawdata);
void Clear() { if (data) delete[] data; data = 0; dataNEW.clear();}
void Save(const string &filename);
void Print(unsigned int count);
int Get(int x, int y);
std::vector<int> getData() {return dataNEW;}
};
int R4sImg::Get(int x, int y) {
if ( y>IMG_HEIGHT || x>IMG_WIDTH )
{printf("ERROR: Out of range");return -9999;}
return data[y*IMG_WIDTH + x];
}
//#include "pixelAlive.h"
#include "TROOT.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TString.h"
#include "TTree.h"
#include "TBranch.h"
#include "TLeaf.h"
#include "TGraph.h"
#include "TMultiGraph.h"
#include "TLegend.h"
#include "TCanvas.h"
bool R4sImg::CreateRaw(const vector<uint16_t> &rawdata)
{
Clear();
if (rawdata.size() < IMG_WIDTH*IMG_HEIGHT) return false;
data = new int[IMG_WIDTH*IMG_HEIGHT];
for (int pos=0; pos<IMG_WIDTH*IMG_HEIGHT; pos++)
{
int value = rawdata[pos];
if (value & 0x1000) // ADC overrange
value = R4S_VALUE_OR;
else if (value & 0x0800) // negative
value -= 0x1000;
data[pos] = value;
dataNEW.push_back(value);
}
return true;
};
//================================================================================
void R4sImg::Print(unsigned int count)
bool ReadImage(R4sImg &map, bool verbose=true)
{
if (!data)
{
printf("<<empty>>\n");
return;
}
if (count > IMG_WIDTH*IMG_HEIGHT) count = IMG_WIDTH*IMG_HEIGHT;
for (unsigned int i=0; i<count; i++)
{
int v = data[i];
if (v == R4S_VALUE_OR) printf(" or"); else printf(" %4i", v);
}
printf("\n");
tb.Daq_Close();
}
tb.Daq_Open(50000);
// prepare ADC
tb.SignalProbeADC(PROBEA_SDATA1, GAIN_1);
// tb.r4s_AdcDelay(0);
tb.r4s_Enable(3); // slow readout
tb.uDelay(100);
void R4sImg::Save(const string &filename)
{
// take data
tb.Daq_Start();
tb.r4s_Start();
tb.uDelay(3000);
tb.Daq_Stop();
if (!data)
{
printf("<<empty>>\n");
return;
}
// stop ADC
tb.r4s_Enable(0);
FILE *f = fopen(filename.c_str(), "wt");
if (!f) return;
// read buffer
vector<uint16_t> data;
unsigned int ret = tb.Daq_Read(data);
int i = 0, x, y;
unsigned int n = data.size();
if (verbose) {printf("--- status = %u; n = %u\n", ret, (unsigned int)(data.size()));}
for (y=IMG_HEIGHT-1; y>=0; y--)
{
for (x=0; x<IMG_WIDTH; x++)
{
int v = Get(x,y);
if (v == R4S_VALUE_OR) fprintf(f, " or"); else fprintf(f, " %4i", v);
}
fputs("\n", f);
}
tb.Daq_Close();
fclose(f);
return map.CreateRaw(data);
}
bool ReadImage(R4sImg &map, bool verbose=true)
bool ReadLine(R4sLine &pixLine, bool verbose=true)
{
tb.Daq_Open(50000);
......@@ -126,7 +86,7 @@ bool ReadImage(R4sImg &map, bool verbose=true)
// take data
tb.Daq_Start();
tb.r4s_Start();
tb.uDelay(3000);
tb.uDelay(100);
tb.Daq_Stop();
// stop ADC
......@@ -141,9 +101,101 @@ bool ReadImage(R4sImg &map, bool verbose=true)
tb.Daq_Close();
return map.CreateRaw(data);
return pixLine.CreateRaw(data);
}
TGraph* CreatePulseShapeGraph(int calX,int calY, int Rgpr, int Rgsh, int Va, int Vcal){
// create arrays with values
int t[256], pulseHeight[256], ped[IMG_WIDTH]={0};// IMG_WIDTH=157
int common_mode_correction;
R4sLine line;
const unsigned int hold_max = 255;
const int ped_measurements = 100;
const int ph_measurements = 10;
//set parameters
tb._SetVA(Va);
int Ia=tb.GetIA()*1000;
printf("Set Va to %d mV, Ia is: %d mA\n",Va,Ia);
tb.r4s_SetRgsh(Rgsh);
tb.r4s_SetRgpr(Rgpr);
printf("Set Rgpr to %d and Rgsh to %d mV\n",Rgpr,Rgsh);
tb.r4s_SetPixCal(calX, calY);
printf("Set cal for pixel x:%d y:%d\n",calX,calY);
// set readoutsequence to read a line only
tb.r4s_SetSeqReadLine();
// measure pedestals
printf("Measureing pedestals...\n");fflush(stdout);
tb.r4s_SetVcal(0);
tb.r4s_SetHoldPos(0);
for (unsigned int i=0;i<ped_measurements;i++)
{
ReadLine(line, false);
for (unsigned int j=0; j<IMG_WIDTH; j++) ped[j] += line.Get(j);
}
for (unsigned int i=0; i<IMG_WIDTH; i++) ped[i] /= ped_measurements;
//printf("pedestals: ");
//for (unsigned int i=0; i<IMG_WIDTH; i++) printf(" %d ", ped[i]);
//printf("\n\n");
// take data
tb.r4s_SetVcal(Vcal);
printf("Set Vcal to %d mA\n\n",Vcal);
printf("Taking data...\n");fflush(stdout);
// loop over all values for hold
for (unsigned int i=0;i<hold_max;i++)
{
tb.r4s_SetHoldPos(i);
for (unsigned int j=0;j<ph_measurements;j++)
{
ReadLine(line, false);
if (calX < 2) common_mode_correction = line.Get(calX+3) - ped[calX+3];
else if (calX > 152) common_mode_correction = line.Get(calX-3) - ped[calX-3];
else common_mode_correction = 0.5 * (line.Get(calX-3) - ped[calX-3] + line.Get(calX+3) - ped[calX+3]);
if (j==0){
pulseHeight[i] = line.Get(calX) - ped[calX] - common_mode_correction;
}
else{
pulseHeight[i] += line.Get(calX) - ped[calX] - common_mode_correction;
}
}
//write values into arrays
t[i] = (i*6.25);//one unit in hold is 6.25ns
pulseHeight[i] /= ph_measurements;
}
printf("Done.\n");
// t, pulseHeight arrays
TGraph *gr = new TGraph( (hold_max), t, pulseHeight);
return gr;
}
//
//================================================================================
bool configure() {
//need to have a function configuring the chip from a file
......@@ -185,20 +237,10 @@ CMD_PROC(seqcalscan)
// printf("Connection to GUI closed.\n");
// }
////////// ANALYSIS
//================================================================================
//#include "pixelAlive.h"
#include "TROOT.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TString.h"
#include "TTree.h"
#include "TBranch.h"
#include "TLeaf.h"
#include "TGraph.h"
////////// ANALYSIS
CMD_PROC(pixelAlive)
......@@ -207,10 +249,10 @@ CMD_PROC(pixelAlive)
ReadImage(map);
map.Print(200);
TFile *rootFile = new TFile("pixelAlive.root","recreate");
// TH1D *h = new TH1D("h","title",10,0,10);
// h->Fill(1);
TFile *rootFile = new TFile("data/pixelAlive.root","recreate");
TH2D *pixelMap = new TH2D("pixelMap","pixel map",IMG_WIDTH,0,IMG_WIDTH,IMG_HEIGHT,0,IMG_HEIGHT);
TH1D *h = new TH1D("h","Distribution",120,-600,600);
//debugging
FILE *f = fopen("debug.txt", "wt");
......@@ -220,8 +262,9 @@ CMD_PROC(pixelAlive)