11 #include <TStopwatch.h>
13 #include "PixTestGainPedestal.hh"
25 fParNtrig(-1), fParShowFits(0), fParExtended(0), fParDumpHists(0) {
32 PixTestGainPedestal::PixTestGainPedestal() :
PixTest() {
39 std::transform(parName.begin(), parName.end(), parName.begin(), ::tolower);
40 for (
unsigned int i = 0; i <
fParameters.size(); ++i) {
43 sval.erase(
remove(sval.begin(), sval.end(),
' '), sval.end());
44 if (!parName.compare(
"ntrig")) {
45 fParNtrig = atoi(sval.c_str());
47 if (!parName.compare(
"showfits")) {
50 fParShowFits = atoi(sval.c_str());
52 if (!parName.compare(
"extended")) {
55 fParExtended = atoi(sval.c_str());
57 if (!parName.compare(
"dumphists")) {
60 fParDumpHists = atoi(sval.c_str());
73 fTestTip = string(Form(
"measure and fit pulseheight vs VCAL (combining low- and high-range)\n"));
74 fSummaryTip = string(
"all ROCs are displayed side-by-side. Note the orientation:")
75 + string(
"\nthe canvas bottom corresponds to the narrow module side with the cable")
80 void PixTestGainPedestal::init() {
84 fDirectory = gFile->GetDirectory(fName.c_str());
93 void PixTestGainPedestal::bookHist(
string ) {
101 PixTestGainPedestal::~PixTestGainPedestal() {
102 LOG(logDEBUG) <<
"PixTestGainPedestal dtor";
113 bigBanner(Form(
"PixTestGainPedestal::doTest() ntrig = %d", fParNtrig));
117 saveGainPedestalParameters();
119 int seconds = t.RealTime();
120 LOG(logINFO) <<
"PixTestGainPedestal::doTest() done, duration: " << seconds <<
" seconds";
131 bigBanner(Form(
"PixTestGainPedestal::fullTest() ntrig = %d", fParNtrig));
137 saveGainPedestalParameters();
139 int seconds = t.RealTime();
140 LOG(logINFO) <<
"PixTestGainPedestal::doTest() done, duration: " << seconds <<
" seconds";
146 std::transform(command.begin(), command.end(), command.begin(), ::tolower);
147 LOG(logDEBUG) <<
"running command: " << command;
148 if (!command.compare(
"measure")) {
152 if (!command.compare(
"fit")) {
156 if (!command.compare(
"save")) {
157 saveGainPedestalParameters();
166 void PixTestGainPedestal::measure() {
167 uint16_t FLAGS = FLAG_FORCE_MASKED;
168 LOG(logDEBUG) <<
" using FLAGS = " << (int)FLAGS;
172 fLpoints.push_back(50);
173 fLpoints.push_back(100);
174 fLpoints.push_back(150);
175 fLpoints.push_back(200);
176 fLpoints.push_back(250);
179 if (1 == fParExtended) {
180 fHpoints.push_back(10);
181 fHpoints.push_back(17);
182 fHpoints.push_back(24);
184 fHpoints.push_back(30);
185 fHpoints.push_back(50);
186 fHpoints.push_back(70);
187 fHpoints.push_back(90);
188 if (1 == fParExtended) {
189 fHpoints.push_back(120);
191 fHpoints.push_back(200);
203 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc) {
204 for (
unsigned int ic = 0; ic < 52; ++ic) {
205 for (
unsigned int ir = 0; ir < 80; ++ir) {
207 ph = pshistBlock + idx;
208 fHists.push_back(ph);
219 vector<pair<uint8_t, vector<pixel> > > rresult, lresult, hresult;
220 for (
unsigned int i = 0; i < fLpoints.size(); ++i) {
221 LOG(logINFO) <<
"scanning low vcal = " << fLpoints[i];
227 copy(rresult.begin(), rresult.end(), back_inserter(lresult));
231 LOG(logCRITICAL) <<
"problem with readout: "<< e.what() <<
" missing " << e.numberMissing <<
" events";
233 if (e.numberMissing > 10) done =
true;
235 LOG(logCRITICAL) <<
"pXar execption: "<< e.what();
238 done = (cnt>2) || done;
244 for (
unsigned int i = 0; i < fHpoints.size(); ++i) {
245 LOG(logINFO) <<
"scanning high vcal = " << fHpoints[i] <<
" (= " << 7*fHpoints[i] <<
" in low range)";
251 copy(rresult.begin(), rresult.end(), back_inserter(hresult));
255 LOG(logCRITICAL) <<
"problem with readout: "<< e.what() <<
" missing " << e.numberMissing <<
" events";
257 if (e.numberMissing > 10) done =
true;
259 LOG(logCRITICAL) <<
"pXar execption: "<< e.what();
262 done = (cnt>2) || done;
266 for (
unsigned int i = 0; i < lresult.size(); ++i) {
267 int dac = lresult[i].first;
269 for (
unsigned int v = 0; v < fLpoints.size(); ++v) {
270 if (fLpoints[v] == dac) {
275 vector<pixel> vpix = lresult[i].second;
276 for (
unsigned int ipx = 0; ipx < vpix.size(); ++ipx) {
277 int roc = vpix[ipx].roc();
278 int ic = vpix[ipx].column();
279 int ir = vpix[ipx].row();
281 double val = vpix[ipx].value();
283 if (idx > -1) fHists[idx]->fill(dacbin+1, val);
288 for (
unsigned int i = 0; i < hresult.size(); ++i) {
289 int dac = hresult[i].first;
291 for (
unsigned int v = 0; v < fHpoints.size(); ++v) {
292 if (fHpoints[v] == dac) {
297 vector<pixel> vpix = hresult[i].second;
298 for (
unsigned int ipx = 0; ipx < vpix.size(); ++ipx) {
299 int roc = vpix[ipx].roc();
300 int ic = vpix[ipx].column();
301 int ir = vpix[ipx].row();
302 double val = vpix[ipx].value();
304 if (idx > -1) fHists[idx]->fill(dacbin+1, val);
313 LOG(logINFO) <<
"PixTestGainPedestal::measure() done ";
320 void PixTestGainPedestal::fit() {
324 string name = Form(
"gainPedestal_c%d_r%d_C%d", 0, 0, 0);
325 TH1D *h1 =
bookTH1D(name, name, 1800, 0., 1800.);
327 h1->SetMaximum(260.);
328 h1->SetNdivisions(506);
329 h1->SetMarkerStyle(20);
330 h1->SetMarkerSize(1.);
334 vector<vector<gainPedestalParameters> > v;
337 a.p0 = a.p1 = a.p2 = a.p3 = 0.;
339 vector<TH1D*> p1list;
340 double fracErr(0.05);
341 for (
unsigned int i = 0; i < rocIds.size(); ++i) {
342 LOG(logDEBUG) <<
"Create hist " << Form(
"gainPedestalP1_C%d", rocIds[i]);
343 h =
bookTH1D(Form(
"gainPedestalP1_C%d", i), Form(
"gainPedestalP1_C%d", rocIds[i]), 100, 0., 2.);
346 vector<gainPedestalParameters> vroc;
347 for (
unsigned j = 0; j < 4160; ++j) {
353 int iroc(0), ic(0), ir(0);
354 for (
unsigned int i = 0; i < fHists.size(); ++i) {
357 for (
int ib = 0; ib < static_cast<int>(fLpoints.size()); ++ib) {
358 h1->SetBinContent(fLpoints[ib]+1, fHists[i]->
get(ib+1));
359 h1->SetBinError(fLpoints[ib]+1, fracErr*fHists[i]->
get(ib+1));
361 for (
int ib = 0; ib < static_cast<int>(fHpoints.size()); ++ib) {
362 h1->SetBinContent(7*fHpoints[ib]+1, fHists[i]->
get(100+ib+1));
363 h1->SetBinError(7*fHpoints[ib]+1, fracErr*fHists[i]->
get(100+ib+1));
366 f =
fPIF->gpTanH(h1);
367 if (h1->Integral() < 1)
continue;
370 TH1D *hc = (TH1D*)h1->Clone(Form(
"gainPedestal_c%d_r%d_C%d", ic, ir, iroc));
371 hc->SetTitle(Form(
"gainPedestal_c%d_r%d_C%d", ic, ir, iroc));
372 string hcname = hc->GetName();
373 LOG(logDEBUG) << hcname;
380 h1->SetTitle(Form(
"gainPedestal_c%d_r%d_C%d", ic, ir, iroc));
381 h1->SetName(Form(
"gainPedestal_c%d_r%d_C%d", ic, ir, iroc));
389 int idx = ic*80 + ir;
390 v[iroc][idx].p0 = f->GetParameter(0);
391 v[iroc][idx].p1 = f->GetParameter(1);
392 v[iroc][idx].p2 = f->GetParameter(2);
393 v[iroc][idx].p3 = f->GetParameter(3);
398 fPixSetup->getConfigParameters()->setGainPedestalParameters(v);
400 copy(p1list.begin(), p1list.end(), back_inserter(
fHistList));
404 string p1MeanString(
""), p1RmsString(
"");
405 for (
unsigned int i = 0; i < p1list.size(); ++i) {
406 p1MeanString += Form(
" %5.3f", p1list[i]->GetMean());
407 p1RmsString += Form(
" %5.3f", p1list[i]->GetRMS());
413 LOG(logINFO) <<
"PixTestGainPedestal::fit() done";
414 LOG(logINFO) <<
"p1 mean: " << p1MeanString;
415 LOG(logINFO) <<
"p1 RMS: " << p1RmsString;
421 void PixTestGainPedestal::saveGainPedestalParameters() {
422 fPixSetup->getConfigParameters()->writeGainPedestalParameters();
427 void PixTestGainPedestal::printHistograms() {
431 int nRocs =
static_cast<int>(rocIds.size());
433 for (
int iroc = 0; iroc < nRocs; ++iroc) {
435 OutputFile.open(Form(
"%s/%s_C%d.dat",
fPixSetup->getConfigParameters()->getDirectory().c_str(),
436 fPixSetup->getConfigParameters()->getGainPedestalFileName().c_str(),
439 OutputFile <<
"Pulse heights for the following Vcal values:" << endl;
440 OutputFile <<
"Low range: ";
441 for (
unsigned int i = 0; i < fLpoints.size(); ++i) OutputFile << fLpoints[i] <<
" ";
443 OutputFile <<
"High range: ";
444 for (
unsigned int i = 0; i < fHpoints.size(); ++i) OutputFile << fHpoints[i] <<
" ";
448 int roc(0), ic(0), ir(0);
450 for (
int i = iroc*4160; i < (iroc+1)*4160; ++i) {
453 LOG(logDEBUG) <<
"BIG CONFUSION?! iroc = " << iroc <<
" roc = " << roc;
457 for (
int ib = 0; ib < static_cast<int>(fLpoints.size()); ++ib) {
458 line += Form(
" %3d", static_cast<int>(fHists[i]->
get(ib+1)));
461 for (
int ib = 0; ib < static_cast<int>(fHpoints.size()); ++ib) {
462 line += Form(
" %3d", static_cast<int>(fHists[i]->
get(100+ib+1)));
465 line += Form(
" Pix %2d %2d", ic, ir);
466 OutputFile << line << endl;
static void replaceAll(std::string &str, const std::string &from, const std::string &to)
in str, replace all occurences of from to to
static int rcr2idx(int iroc, int icol, int irow)
convert ROC/COL/ROW into idx
std::vector< std::pair< uint8_t, std::vector< pixel > > > getPulseheightVsDAC(std::string dacName, uint8_t dacMin, uint8_t dacMax, uint16_t flags, uint16_t nTriggers)
bool setDAC(std::string dacName, uint8_t dacValue, uint8_t rocI2C)
PixSetup * fPixSetup
all necessary stuff in one place
void fullTest()
function called when FullTest is running; most often this is simply calling doTest() ...
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
std::vector< std::pair< std::string, std::string > > fParameters
the parameters of this test
int getIdxFromId(int id)
provide the mapping between ROC index and ID
void maskAllPixels(bool mask, uint8_t rocid)
TDirectory * fDirectory
where the root histograms will end up
void restoreDacs(bool verbose=false)
restore all DACs
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
std::vector< uint8_t > getEnabledRocIDs()
void testAllPixels(bool enable)
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
void runCommand(std::string command)
allow execution of any button in the test
TH1D * bookTH1D(std::string sname, std::string title, int nbins, double xmin, double xmax)
book a TH1D, adding version information to the name and title
void cacheDacs(bool verbose=false)
cache all DACs
std::list< TH1 * > fHistList
list of histograms available in PixTab::next and PixTab::previous
void setTitles(TH1 *h, const char *sx, const char *sy, float size=0.05, float xoff=1.1, float yoff=1.1, float lsize=0.05, int font=42)
utility to set histogram titles
static void idx2rcr(int idx, int &iroc, int &icol, int &irow)
and back again
PixInitFunc * fPIF
function instantiation and automatic initialization
void update()
signal to PixTab to update the canvas
pxar::pxarCore * fApi
pointer to the API
void init()
sets all test parameters
void doTest()
function connected to "DoTest" button of PixTab