7 void phOpt(
string rootfile =
"phOpt.root",
string cfgdirectory =
"testROC") {
10 configParameters->setDirectory(cfgdirectory);
11 string cfgFile = configParameters->getDirectory() + string(
"/configParameters.dat");
12 configParameters->readConfigParameterFile(cfgFile);
19 cout <<
"pxar: dumping results into " << rootfile << endl;
20 TFile *rfile = TFile::Open(rootfile.c_str(),
"RECREATE");
24 PixTest *pt = factory->createTest(
"DacScan", ap);
33 for (
unsigned int io = 0; io < 26; ++io) {
34 for (
unsigned int is = 0; is < 52; ++is) {
35 pt->
setDAC(
"phoffset", io*10);
36 pt->
setDAC(
"phscale", is*5);
38 h1 = (TH1D*)rfile->Get(Form(
"DacScan/ph_Vcal_c11_r20_C0_V%d", cycle));
39 h1->SetTitle(Form(
"ph_Vcal_c11_r20_C0_V%d phscale=%d phoffset=%d", cycle, is*5, io*10));
55 void ana(
string rootfile =
"phOpt.root") {
56 TFile *f = TFile::Open(rootfile.c_str());
64 TIter next(gDirectory->GetListOfKeys(););
66 double maxPh(0.), minVcal(60);
67 TH1D *hmax(0), *hmin(0);
68 TCanvas *c0 =
new TCanvas(
"C0");
70 while ((obj = (TObject*)next())) {
71 h = (TH1D*)gDirectory->Get(obj->GetName());
74 cout <<
"problem with " << obj->GetName() << endl;
78 double integral = h->Integral();
79 if (integral < 100.)
continue;
81 double plateau = h->GetMaximum();
82 double vcal = h->FindFirstBinAbove(1.);
84 if (plateau > maxPh && vcal < minVcal+10) {
89 if (vcal > 10 && vcal < minVcal) {
94 cout <<
"h = " << h <<
" obj = " << obj <<
" name: " << h->GetName() <<
" integral: " << integral << endl;
111 void Opt_fit(
string rootfile =
"phOpt.root") {
112 TFile *f = TFile::Open(rootfile.c_str());
116 int OptDistance(255);
119 TCanvas *c0 =
new TCanvas(
"C0");
121 unsigned int io, is, is_opt=999;
126 double upEd_dist=255, lowEd_dist=255;
127 unsigned int io_opt=999;
133 for(is=0; is<52; is++){
134 h = (TH1D*)gDirectory->Get(Form(
"DacScan/ph_Vcal_c11_r20_C0_V%d", 52*io+is));
135 cout<<h->GetTitle()<<endl;
138 h->SetBinContent(1,0.);
139 bin_min = h->FindFirstBinAbove(1.);
140 upEd_dist = abs(h->GetBinContent(h->FindFixBin(255)) - (255 - safety_margin));
141 lowEd_dist = abs(h->GetBinContent(bin_min) - safety_margin);
142 dist = (upEd_dist > lowEd_dist ) ? (upEd_dist) : (lowEd_dist);
150 cout<<
"PH optimization failed"<<endl;
154 cout<<
"PH Scale value chosen: " << is_opt <<
"with distance " << bestDist << endl;
159 for(io=0; io<26; io++){
160 h = (TH1D*)gDirectory->Get(Form(
"DacScan/ph_Vcal_c11_r20_C0_V%d", 52*io+is_opt));
161 cout<<h->GetTitle()<<endl;
163 h->SetBinContent(1,0.);
164 double plateau = h->GetMaximum();
165 bin_min = h->FindFirstBinAbove(1.);
166 double minPH = h->GetBinContent(bin_min);
168 dist = abs(minPH - (255 - plateau));
170 cout<<
"offset = " << io <<
", plateau = " << plateau <<
", minPH = " << minPH <<
", distance = " << dist << endl;
172 if (dist < bestDist){
185 for(is=0; is<52; is++){
186 h = (TH1D*)gDirectory->Get(Form(
"DacScan/ph_Vcal_c11_r20_C0_V%d", 52*io_opt+is));
187 cout<<h->GetTitle()<<endl;
190 h->SetBinContent(1,0.);
191 bin_min = h->FindFirstBinAbove(1.);
192 upEd_dist = abs(h->GetBinContent(h->FindFixBin(255)) - (255 - safety_margin));
193 lowEd_dist = abs(h->GetBinContent(bin_min) - safety_margin);
194 dist = (upEd_dist < lowEd_dist ) ? (upEd_dist) : (lowEd_dist);
203 cout<<
"PH optimization failed (stretching)"<<endl;
208 hopt = (TH1D*)gDirectory->Get(Form(
"DacScan/ph_Vcal_c11_r20_C0_V%d", 52*io_opt+is_opt));
209 cout <<
"h = " << hopt <<
" name: " << h->GetName() << endl;
210 cout <<
"optimal PH parameters:" << endl <<
"PH scale = " << is_opt << endl <<
"PH offset = " << io_opt << endl <<
"Best Distance " << bestDist << endl ;
215 void riseLengthMap(
string rootfile =
"phOpt.root") {
216 TFile *f = TFile::Open(rootfile.c_str());
220 TH2F *hmap =
new TH2F(
"hmap",
"PH rise lenght map", 26, -5., 255, 52, -2.5, 257.5);
221 TCanvas *c0 =
new TCanvas(
"C0");
224 int bin_min, bin_max;
225 double lenght, plateau, minPH;
227 for(io=0; io<26; io++){
228 for(is=0; is<52; is++){
229 h = (TH1D*)gDirectory->Get(Form(
"DacScan/ph_Vcal_c11_r20_C0_V%d", 52*io+is));
230 cout<<h->GetTitle()<<endl;
233 h->SetBinContent(1,0.);
234 bin_min = h->FindFirstBinAbove(1.);
235 plateau = h->GetMaximum();
236 bin_min = h->FindFirstBinAbove(1.);
237 bin_max = h->FindFirstBinAbove(0.9*plateau);
238 double minPH = h->GetBinContent(bin_min);
240 lenght = sqrt( pow((h->GetBinCenter(bin_max) - h->GetBinCenter(bin_min) ),2) + pow((plateau*0.9 - h->GetBinContent(bin_min) ),2) );
242 hmap->Fill(io*10, is*5, lenght);
245 hmap->GetXaxis()->SetTitle(
"PH offset [DAC]");
246 hmap->GetYaxis()->SetTitle(
"PH scale [DAC]");
247 gStyle->SetPalette(1);
259 const Int_t NRGBs = 5;
260 const Int_t NCont = 255;
262 Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
263 Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
264 Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
265 Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
266 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
267 gStyle->SetNumberContours(NCont);
virtual void doTest()
function connected to "DoTest" button of PixTab
virtual void setDAC(std::string parName, uint8_t val)
allow setting DACs in scripts for entire DUT
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter