9 #include <TStopwatch.h>
11 #include "PixTestScurves.hh"
14 #include "rsstools.hh"
23 fParDac(""), fParNtrig(-1), fParNpix(-1), fParDacLo(-1), fParDacHi(-1), fParDacsPerStep(-1), fAdjustVcal(1), fDumpAll(-1), fDumpProblematic(-1) {
30 PixTestScurves::PixTestScurves() :
PixTest() {
37 std::transform(parName.begin(), parName.end(), parName.begin(), ::tolower);
38 for (
unsigned int i = 0; i <
fParameters.size(); ++i) {
41 sval.erase(
remove(sval.begin(), sval.end(),
' '), sval.end());
42 if (!parName.compare(
"ntrig")) {
43 fParNtrig = atoi(sval.c_str());
45 if (!parName.compare(
"npix")) {
46 fParNpix = atoi(sval.c_str());
48 if (!parName.compare(
"dac")) {
51 if (!parName.compare(
"daclo")) {
52 fParDacLo = atoi(sval.c_str());
54 if (!parName.compare(
"dachi")) {
55 fParDacHi = atoi(sval.c_str());
57 if (!parName.compare(
"dacs/step")) {
58 fParDacsPerStep = atoi(sval.c_str());
61 if (!parName.compare(
"adjustvcal")) {
64 fAdjustVcal = atoi(sval.c_str());
68 if (!parName.compare(
"dumpall")) {
71 fDumpAll = atoi(sval.c_str());
75 if (!parName.compare(
"dumpallproblematic")) {
78 fDumpProblematic = atoi(sval.c_str());
93 fTestTip = string(Form(
"measure and fit s-curves for DAC %s\n", fParDac.c_str()));
94 fSummaryTip = string(
"all ROCs are displayed side-by-side. Note the orientation:")
95 + string(
"\nthe canvas bottom corresponds to the narrow module side with the cable")
96 + string(
"\nexplanations for all plots: ")
97 + string(
"thr_* shows the map of the s-curve thresholds")
98 + string(
"\nsig_* shows the map of the s-curve widths")
99 + string(
"\ndist_* shows the distribution/projections of the threshold and width maps")
104 void PixTestScurves::init() {
108 fDirectory = gFile->GetDirectory(fName.c_str());
117 void PixTestScurves::bookHist(
string name) {
120 LOG(logDEBUG) <<
"nothing done with " << name;
126 PixTestScurves::~PixTestScurves() {
127 LOG(logDEBUG) <<
"PixTestScurves dtor";
137 bigBanner(Form(
"PixTestScurves::doTest() ntrig = %d", fParNtrig));
166 bigBanner(Form(
"PixTestScurves::fullTest() ntrig = %d", fParNtrig));
168 fParDac =
"VthrComp";
171 fParDacsPerStep = 40;
177 fParDacsPerStep = 40;
180 int seconds = t.RealTime();
181 LOG(logINFO) <<
"PixTestScurves::fullTest() done, duration: " << seconds <<
" seconds";
189 std::transform(command.begin(), command.end(), command.begin(), ::tolower);
190 LOG(logDEBUG) <<
"running command: " << command;
191 if (!command.compare(
"thrmap")) {
195 if (!command.compare(
"fits")) {
199 if (!command.compare(
"scurves")) {
208 void PixTestScurves::scurves() {
212 string command(fParDac);
213 std::transform(command.begin(), command.end(), command.begin(), ::tolower);
214 if (!command.compare(
"vthrcomp") && fAdjustVcal) {
215 LOG(logINFO) <<
"adjusting VCAL to have VthrComp average threshold at default VthrComp";
224 if (fDumpAll) results |= 0x20;
225 if (fDumpProblematic) results |= 0x10;
227 int FLAG = FLAG_FORCE_MASKED;
228 vector<TH1*> thr0 =
scurveMaps(fParDac,
"scurve"+fParDac, fParNtrig, fParDacLo, fParDacHi, fParDacsPerStep, results, 1, FLAG);
229 if (thr0.size() < 1) {
230 LOG(logERROR) <<
"no scurve result histograms received?!";
234 TH1 *h1 = (*fDisplayedHist);
239 string hname(
""), scurvesMeanString(
""), scurvesRmsString(
"");
240 for (
unsigned int i = 0; i < thr0.size(); ++i) {
241 hname = thr0[i]->GetName();
242 if (!thr0[i])
continue;
244 if (string::npos == hname.find(
"dist_thr_"))
continue;
245 scurvesMeanString += Form(
"%6.2f ", thr0[i]->GetMean());
246 scurvesRmsString += Form(
"%6.2f ", thr0[i]->GetRMS());
249 LOG(logINFO) <<
"PixTestScurves::scurves() done ";
250 LOG(logINFO) << Form(
"%s mean: ", fParDac.c_str()) << scurvesMeanString;
251 LOG(logINFO) << Form(
"%s RMS: ", fParDac.c_str()) << scurvesRmsString;
257 void PixTestScurves::thrMap() {
264 LOG(logINFO) <<
"PixTestScurves::thrMap() start: "
265 << fParDac <<
": " << fParDacLo <<
" .. " << fParDacHi
266 <<
" ntrig = " << fParNtrig;
267 vector<TH1*> thr1 =
thrMaps(fParDac,
"thr"+fParDac, fParDacLo, fParDacHi, fParNtrig);
271 LOG(logINFO) <<
"PixTestScurves::thrMap() done ";
277 void PixTestScurves::fitS() {
281 if (!fParDac.compare(
"Vcal")) {
282 TH1D *h = (TH1D*)
fDirectory->Get(
"scurveVcal_Vcal_c51_r62_C0");
284 fPIF->fLo = fParDacLo+1;
285 fPIF->fHi = fParDacHi;
286 TF1 *f =
fPIF->errScurve(h);
287 f->SetLineColor(kBlue);
289 for (
int iroc = 0; iroc < 1; ++iroc) {
290 for (
int ic = 0; ic < 2; ++ic) {
291 for (
int ir = 0; ir < 10; ++ir) {
293 h = (TH1D*)
fDirectory->Get(Form(
"scurveVcal_Vcal_c%d_r%d_C%d", ic, ir, iroc));
294 if (0 == h)
continue;
296 h->Fit(f,
"qr",
"",
fPIF->fLo,
fPIF->fHi);
298 double Threshold = f->GetParameter(0);
299 double ThresholdE = f->GetParError(0);
300 cout << Threshold <<
" +/- " << ThresholdE << endl;
307 string dacname(fParDac);
308 std::transform(dacname.begin(), dacname.end(), dacname.begin(), ::tolower);
309 if (!dacname.compare(
"vthrcomp")) {
310 TH1D *h = (TH1D*)
fDirectory->Get(
"scurveVthrComp_VthrComp_c51_r62_C0");
313 for (
int iroc = 0; iroc < 1; ++iroc) {
314 for (
int ic = 0; ic < 10; ++ic) {
315 for (
int ir = 0; ir < 20; ++ir) {
316 h = (TH1D*)
fDirectory->Get(Form(
"scurveVthrComp_VthrComp_c%d_r%d_C%d", ic, ir, iroc));
317 if (0 == h)
continue;
318 fPIF->fLo = fParDacLo+1;
319 fPIF->fHi = h->FindLastBinAbove(0.5*h->GetMaximum());
320 TF1 *f =
fPIF->errScurve(h);
321 f->SetLineColor(kBlue);
322 if (
fPIF->doNotFit()) {
324 h->Fit(f,
"qr",
"",
fPIF->fLo,
fPIF->fHi);
326 double Threshold = f->GetParameter(0);
327 double ThresholdE = f->GetParError(0);
328 cout << Threshold <<
" +/- " << ThresholdE << endl;
340 void PixTestScurves::adjustVcal() {
343 uint16_t FLAGS = FLAG_FORCE_MASKED;
346 unsigned nrocs = rocIds.size();
348 vector<vector<pair<int, int> > > dead =
deadPixels(5);
359 for (
unsigned int iroc = 0; iroc < nrocs; ++iroc){
360 h =
bookTH2D(Form(
"adjustVcal_C%d", rocIds[iroc]), Form(
"adjustVcal_C%d", rocIds[iroc]), 256, 0., 256., 256, 0., 256.);
369 vector<pair<uint8_t, pair<uint8_t, vector<pixel> > > > results =
373 for (
unsigned int i = 0; i < results.size(); ++i) {
374 pair<uint8_t, pair<uint8_t, vector<pixel> > > v = results[i];
376 pair<uint8_t, vector<pixel> > w = v.second;
378 vector<pixel> wpix = w.second;
380 for (
unsigned ipix = 0; ipix < wpix.size(); ++ipix) {
382 hv[idx]->Fill(idac1, idac2, wpix[ipix].value());
386 for (
unsigned int iroc = 0; iroc < nrocs; ++iroc){
387 hv[iroc]->Draw(
"colz");
392 TH1D *h0 = hv[iroc]->ProjectionY(
"h0_px", vcthr, vcthr+1);
393 int vcalthr = h0->FindFirstBinAbove(0.5*ntrig);
396 LOG(logDEBUG) <<
"ROC " <<
static_cast<int>(rocIds[iroc]) <<
" vthrcomp = " << vcthr <<
" -> vcal = " << vcalthr;
397 vcal.push_back(vcalthr);
401 LOG(logCRITICAL) <<
"problem with readout: "<< e.what() <<
" setting vcal = 100";
402 for (
unsigned int iroc = 0; iroc < nrocs; ++iroc){
407 for (
unsigned int i = 0; i < nrocs; ++i) {
static void replaceAll(std::string &str, const std::string &from, const std::string &to)
in str, replace all occurences of from to to
std::vector< std::vector< std::pair< int, int > > > deadPixels(int ntrig, bool scanCalDel=false)
create vector (per ROC) of vector of dead pixels
std::map< TH1 *, std::string > fHistOptions
options can be stored with each histogram
bool setDAC(std::string dacName, uint8_t dacValue, uint8_t rocI2C)
void testPixel(uint8_t column, uint8_t row, bool enable)
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
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
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
virtual std::string getHistOption(TH1 *)
get the hist display options (if stored in fHistOptions)
void cacheDacs(bool verbose=false)
cache all DACs
std::list< TH1 * > fHistList
list of histograms available in PixTab::next and PixTab::previous
std::vector< std::pair< uint8_t, std::pair< uint8_t, std::vector< pixel > > > > getEfficiencyVsDACDAC(std::string dac1name, uint8_t dac1min, uint8_t dac1max, std::string dac2name, uint8_t dac2min, uint8_t dac2max, uint16_t flags, uint16_t nTriggers)
void fullTest()
function called when FullTest is running; most often this is simply calling doTest() ...
PixInitFunc * fPIF
function instantiation and automatic initialization
TH2D * bookTH2D(std::string sname, std::string title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double max)
book a TH2D, adding version information to the name and title
void maskPixel(uint8_t column, uint8_t row, bool mask)
void doTest()
function connected to "DoTest" button of PixTab
void update()
signal to PixTab to update the canvas
uint8_t getDAC(size_t rocId, std::string dacName)
pxar::pxarCore * fApi
pointer to the API
std::vector< TH1 * > scurveMaps(std::string dac, std::string name, int ntrig=10, int daclo=0, int dachi=255, int dacsperstep=-1, int result=15, int ihit=1, int flag=FLAG_FORCE_MASKED)
void init()
sets all test parameters
void runCommand(std::string command)
allow execution of any button in the test
std::vector< TH1 * > thrMaps(std::string dac, std::string name, uint8_t dacmin, uint8_t dachi, int ntrig, uint16_t flag=0)
returns TH2D's for the threshold, the user flag argument is intended for selecting calS and will be O...