Commit 01a629b8 authored by rohe's avatar rohe
Browse files

pulseShapeGraph changend

parent 22907314
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
* author: Beat Meier * author: Beat Meier
* modified: 31.8.2007 * modified: 31.8.2007
* *
* rev: * rev: Tilman Rohe
* dat: 22.08.2017
* *
* ------------------------------------------------------------- * -------------------------------------------------------------
*/ */
...@@ -16,10 +17,30 @@ ...@@ -16,10 +17,30 @@
#include "cmd.h" #include "cmd.h"
#include "datalink.h" #include "datalink.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"
#define IMG_WIDTH 157 #define IMG_WIDTH 157
#define IMG_HEIGHT 163 #define IMG_HEIGHT 163
#define R4S_VALUE_OR 4096 #define R4S_VALUE_OR 4096
//================================================================================
class R4sImg class R4sImg
{ {
int *data; int *data;
...@@ -144,6 +165,223 @@ bool ReadImage(R4sImg &map, bool verbose=true) ...@@ -144,6 +165,223 @@ bool ReadImage(R4sImg &map, bool verbose=true)
return map.CreateRaw(data); return map.CreateRaw(data);
} }
//================================================================================
//
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;}
};
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);
}
bool ReadLine(R4sLine &pixLine, bool verbose=true)
{
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);
// take data
tb.Daq_Start();
tb.r4s_Start();
tb.uDelay(100);
tb.Daq_Stop();
// stop ADC
tb.r4s_Enable(0);
// read buffer
vector<uint16_t> data;
unsigned int ret = tb.Daq_Read(data);
unsigned int n = data.size();
if (verbose) {printf("--- status = %u; n = %u\n", ret, (unsigned int)(data.size()));}
tb.Daq_Close();
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 pedestal
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() { bool configure() {
//need to have a function configuring the chip from a file //need to have a function configuring the chip from a file
...@@ -185,20 +423,10 @@ CMD_PROC(seqcalscan) ...@@ -185,20 +423,10 @@ CMD_PROC(seqcalscan)
// printf("Connection to GUI closed.\n"); // printf("Connection to GUI closed.\n");
// } // }
////////// ANALYSIS
//================================================================================
//#include "pixelAlive.h" ////////// ANALYSIS
#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"
CMD_PROC(pixelAlive) CMD_PROC(pixelAlive)
...@@ -342,56 +570,78 @@ CMD_PROC(pulseShape) { ...@@ -342,56 +570,78 @@ CMD_PROC(pulseShape) {
//pulse shape, creating a graph //pulse shape, creating a graph
CMD_PROC(pulseShapeGraph) { CMD_PROC(pulseShapeGraph) {
int calX,calY, Rg, Ia; int calX,calY, Rgpr, Rgsh, Va, Vcal;
PAR_INT(calX,0,255); PAR_INT(calX,0,255);
PAR_INT(calY,0,255); PAR_INT(calY,0,255);
PAR_INT(Rg,0,2500); PAR_INT(Rgpr,0,2500);
PAR_INT(Ia,0,2000); PAR_INT(Rgsh,0,2500);
PAR_INT(Va,0,4000);
PAR_INT(Vcal,0,2500);
TFile *rootFile = new TFile("data/pulseShapeGraph.root","update"); TFile *rootFile = new TFile("data/pulseShapeGraph.root","update");
// create arrays with values
int t[256], pulseHight[256];
R4sImg map;
const unsigned int hold_max = 255;
//set parameters and get the data
tb._SetIA(Ia*10);
printf("Set Ia to %d mA\n",Ia);
tb.r4s_SetRgsh(Rg);
tb.r4s_SetRgpr(Rg);
printf("Set Rgpr and Rgsh to %d mV\n",Rg);
tb.r4s_SetPixCal(calX, calY);
printf("Set cal for pixel x:%d y:%d\n",calX,calY);
printf("Taking data...");fflush(stdout);
// loo over all values for hold
for (unsigned int i=0;i<hold_max;i++)
{
tb.r4s_SetHoldPos(i);
ReadImage(map,false);
//write values into arrays
t[i] = (i*5);//one unit in hold is 5ns
pulseHight[i] = map.Get(calX,calY);
}
printf("Done.\n");
// t, pulseHight arrays // t, pulseHeight arrays
TGraph *gr = new TGraph( (hold_max), t, pulseHight); TGraph *gr;
gr = CreatePulseShapeGraph(calX,calY,Rgpr,Rgsh,Va,Vcal);
char GraphName[60]; char GraphName[60];
sprintf(GraphName, "PulseShapeX%dY%dRg%dIa%d",calX,calY,Rg,Ia); sprintf(GraphName, "PulseShapeX%dY%dRgpr%dRgsh%dVa%dVcal%d",calX,calY,Rgpr,Rgsh,Va,Vcal);
gr->Write(GraphName); gr->Write(GraphName);
rootFile->Close(); rootFile->Close();
}
CMD_PROC(pulseShapeRgsh) {
int calX,calY, Rgpr, Rgsh_min, Rgsh_max, Rgsh_step, Va, Vcal;
PAR_INT(calX,0,255);
PAR_INT(calY,0,255);
PAR_INT(Rgpr,0,2500);
PAR_INT(Rgsh_min,0,2500);
PAR_INT(Rgsh_max,0,2500);
PAR_INT(Rgsh_step,0,2500);
PAR_INT(Va,0,4000);
PAR_INT(Vcal,0,2500);
if (Rgsh_max <= Rgsh_min){
printf("Rgsh_max <= Rgsh_min, values swopped:\n");
int help = Rgsh_max; Rgsh_max = Rgsh_min; Rgsh_min = help;
}
// Calculate number of steps
if (Rgsh_step > (Rgsh_max-Rgsh_min)) Rgsh_step == (Rgsh_max-Rgsh_min);
int nSteps = int((Rgsh_max-Rgsh_min)/Rgsh_step) + 1;
printf("Rgsh_min: %d, Rgsh_max: %d, Rgsh_step: %d, number of measurements: %d\n",Rgsh_min,Rgsh_max,Rgsh_step,nSteps);
TMultiGraph *mg = new TMultiGraph();
TLegend *leg;
TGraph *gr[nSteps];
TFile *rootFile = new TFile("data/pulseShapeGraph.root","update");
//TCanvas *c1;
//TH2F *hpx;
char GraphName[80], mgName[80];
for (int i=0; i<nSteps; i++){
int Rgsh = Rgsh_min + (i*Rgsh_step);
gr[i]=CreatePulseShapeGraph(calX,calY,Rgpr,Rgsh,Va,Vcal);
mg->Add(gr[i]);
sprintf(GraphName, "PulseShapeX%dY%dRgpr%dRgsh%dVa%dVcal%d",calX,calY,Rgpr,Rgsh,Va,Vcal);
gr[i]->Write(GraphName);
}
sprintf(mgName, "PulseShapeX%dY%dRgpr%dRgsh%dto%dVa%dVcal%d",calX,calY,Rgpr,Rgsh_min,Rgsh_max,Va,Vcal);
mg -> Write(mgName);
rootFile->Close();
} }
...@@ -21,7 +21,8 @@ CMD_REG(seqcalscan, "", "Load calibrate scan sequence") ...@@ -21,7 +21,8 @@ CMD_REG(seqcalscan, "", "Load calibrate scan sequence")
//analysis //analysis
//CMD_REG(test, "" , "print 'Hello World!'") //CMD_REG(test, "" , "print 'Hello World!'")
CMD_REG(pixelAlive, "" ,"performs a pixel alive test") CMD_REG(pixelAlive, "" ,"performs a pixel alive test")
CMD_REG(pixelDist,"<iterations>","distribution of calibration pulses per pixel"); CMD_REG(pixelDist,"<iterations>","distribution of calibration pulses per pixel")
CMD_REG(pulseShape,"<x> <y>","analogue out as a function of the hold position, creating a tree "); CMD_REG(pulseShape,"<x> <y>","analogue out as a function of the hold position, creating a tree ")
CMD_REG(pulseShapeGraph,"<x> <y> <Rg> <Ia>","analogue out as a function of the hold position. Rgsh=Rgpr and Ia can be set. Output is a graph created in a rootfile"); CMD_REG(pulseShapeGraph,"<x> <y> <Rgpr><Rgsh> <Va> <Vcal>","analogue out as a function of the hold position. Rgsh, Rgpr and Va can be set. Output is a graph created in a rootfile")
CMD_REG(pulseShapeRgsh, "<x> <y> <Rgpr><Rgsh min><Rgsh max><Rgsh step> <Va> <Vcal>","returns pulse shape graphs for Rgsh scanned in a root file")
//CMD_REG(gui, "", "Start graphical user interface"); //CMD_REG(gui, "", "Start graphical user interface");
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment