5 #include "PixTestDaq.hh"
18 PixTestDaq::
PixTestDaq(
PixSetup *a, std::
string name) :
PixTest(a, name), fParDelayTBM(0), fParFillTree(0), fParStretch(0), fParTriggerFrequency(0), fParNtrig(0), fParIter(0), fRunDaqTrigger(0), fParSeconds(0) {
21 LOG(logDEBUG) <<
"PixTestDaq ctor(PixSetup &a, string, TGTab *)";
24 fPhCal.setPHParameters(fPixSetup->getConfigParameters()->getGainPedestalParameters());
25 fPhCalOK = fPhCal.initialized();
29 PixTestDaq::PixTestDaq() :
PixTest() {
30 LOG(logDEBUG) <<
"PixTestDaq ctor()";
35 PixTestDaq::~PixTestDaq() {
36 LOG(logDEBUG) <<
"PixTestDaq dtor";
38 if (fTree && fParFillTree) fTree->Write();
42 void PixTestDaq::init() {
43 LOG(logDEBUG) <<
"PixTestDaq::init()";
45 fDirectory = gFile->GetDirectory(fName.c_str());
54 fTestTip = string(
"Run DAQ seconds - data from each run will be added to the same histogram.") ;
55 fSummaryTip = string(
"to be implemented") ;
56 fStopTip = string(
"Stop DAQ and save data.");
62 fParOutOfRange =
false;
63 std::transform(parName.begin(), parName.end(), parName.begin(), ::tolower);
64 for (
unsigned int i = 0; i <
fParameters.size(); ++i) {
67 if (!parName.compare(
"delaytbm")) {
70 fParDelayTBM = !(atoi(sval.c_str()) == 0);
73 if (!parName.compare(
"filltree")) {
76 fParFillTree = !(atoi(sval.c_str()) == 0);
79 if (!parName.compare(
"clockstretch")) {
80 fParStretch = atoi(sval.c_str());
83 if (!parName.compare(
"trgfrequency(khz)")){
84 fParTriggerFrequency = atoi(sval.c_str());
85 if (fParTriggerFrequency == 0) {
86 LOG(logWARNING) <<
"PixTestDaq::setParameter() trgfrequency must be different from zero";
87 found =
false; fParOutOfRange =
true;
90 if (!parName.compare(
"trgnumber")) {
91 fParNtrig = atoi(sval.c_str());
94 if (!parName.compare(
"iterations")) {
95 fParIter = atoi(sval.c_str());
98 if (!parName.compare(
"daqseconds")){
99 fParSeconds = atoi(sval.c_str());
107 void PixTestDaq::doStop(){
110 LOG(logINFO) <<
"Stop pressed. Ending test.";
114 void PixTestDaq::doRunMaskHotPixels() {
118 bookHist(
"hotpixels");
121 for (
unsigned int i = 0; i < v.size(); ++i) v[i]->Reset();
133 if (command ==
"stop")
135 else if (!command.compare(
"maskhotpixels")) {
136 doRunMaskHotPixels();
139 else if (!command.compare(
"rundaqtrg")) {
140 fRunDaqTrigger =
true;
143 else if (!command.compare(
"rundaqseconds")) {
144 fRunDaqTrigger =
false;
148 LOG(logINFO) <<
"Command " << command <<
" not implemented.";
152 void PixTestDaq::bookHist(
string ) {
155 fHitMap.clear(); fPhmap.clear(); fPh.clear(); fQmap.clear(); fQ.clear();
161 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
162 h2 =
bookTH2D(Form(
"hits_C%d", rocIds[iroc]), Form(
"hits_C%d", rocIds[iroc]), 52, 0., 52., 80, 0., 80.);
167 fHitMap.push_back(h2);
169 p2 =
bookTProfile2D(Form(
"phMap_C%d", rocIds[iroc]), Form(
"phMap_C%d", rocIds[iroc]), 52, 0., 52., 80, 0., 80.);
174 fPhmap.push_back(p2);
176 h1 =
bookTH1D(Form(
"ph_C%d", rocIds[iroc]), Form(
"ph_C%d", rocIds[iroc]), 256, 0., 256.);
182 p2 =
bookTProfile2D(Form(
"qMap_C%d", rocIds[iroc]), Form(
"qMap_C%d", rocIds[iroc]), 52, 0., 52., 80, 0., 80.);
189 h1 =
bookTH1D(Form(
"q_C%d", rocIds[iroc]), Form(
"q_C%d", rocIds[iroc]), 200, 0., 1000.);
192 setTitles(h1,
"Q [Vcal]",
"Entries/bin");
198 void PixTestDaq::ProcessData(uint16_t numevents){
200 LOG(logDEBUG) <<
"Getting Event Buffer";
201 std::vector<pxar::Event> daqdat;
204 for (
unsigned int i = 0; i < numevents; i++) {
207 if (evt.pixels.size() > 0)
208 daqdat.push_back(evt);
214 LOG(logDEBUG) <<
"Processing Data: " << daqdat.size() <<
" events.";
220 for (std::vector<pxar::Event>::iterator it = daqdat.begin(); it != daqdat.end(); ++it) {
221 pixCnt += it->pixels.size();
225 fTreeEvent.header = it->header;
227 fTreeEvent.trailer = it->trailer;
230 for (
unsigned int ipix = 0; ipix < it->pixels.size(); ++ipix) {
233 LOG(logWARNING) <<
"PixTestDaq::ProcessData() wrong 'idx' value --> return";
236 fHitMap[idx]->Fill(it->pixels[ipix].column(), it->pixels[ipix].row());
237 fPhmap[idx]->Fill(it->pixels[ipix].column(), it->pixels[ipix].row(), it->pixels[ipix].value());
238 fPh[idx]->Fill(it->pixels[ipix].value());
241 q =
static_cast<uint16_t
>(fPhCal.vcal(it->pixels[ipix].roc(), it->pixels[ipix].column(),
242 it->pixels[ipix].row(), it->pixels[ipix].value()));
248 fQmap[idx]->Fill(it->pixels[ipix].column(), it->pixels[ipix].row(), q);
249 if (fParFillTree && ipix < 20000) {
251 fTreeEvent.proc[ipix] = it->pixels[ipix].roc();
252 fTreeEvent.pcol[ipix] = it->pixels[ipix].column();
253 fTreeEvent.prow[ipix] = it->pixels[ipix].row();
254 fTreeEvent.pval[ipix] = it->pixels[ipix].value();
255 fTreeEvent.pq[ipix] = q;
258 if (fParFillTree) fTree->Fill();
262 TH2D* h2 = (TH2D*)(fHitMap.back());
267 LOG(logINFO) << Form(
"events read:%5ld, pixels seen:%3d, hist entries: %4d",
268 daqdat.size(), pixCnt,
static_cast<int>(fHitMap[0]->GetEntries()));
272 void PixTestDaq::doDaqRun() {
278 if (fParOutOfRange)
return;
280 banner(Form(
"PixTestDaq::doDaqRun() start.") );
286 if(
fHistList.size() == 0) bookHist(
"daq");
291 for (
unsigned int i = 0; i < fHotPixels.size(); ++i) {
292 vector<pair<int, int> > hot = fHotPixels[i];
293 for (
unsigned int ipix = 0; ipix < hot.size(); ++ipix) {
294 LOG(logINFO) <<
"ROC " <<
getIdFromIdx(i) <<
" masking hot pixel " << hot[ipix].first <<
"/" << hot[ipix].second;
302 LOG(logINFO) <<
"PixTestDaq:: Number of masked pixels:";
303 for (
unsigned int iroc = 0; iroc < rocIds.size(); ++iroc) {
304 LOG(logINFO) <<
"PixTestDaq:: " <<
fApi->
_dut->
getNMaskedPixels(static_cast<int>(iroc)) <<
" - ROC " <<
static_cast<int>(iroc);
310 int totalPeriod =
prepareDaq(fParTriggerFrequency, 50);
313 LOG(logINFO) <<
"PG set to have trigger frequency = " << fParTriggerFrequency <<
" kHz";
316 LOG(logINFO) <<
"set TBM register delays = 0x40";
325 if (fRunDaqTrigger) {
326 LOG(logINFO) <<
"Sending " << fParNtrig <<
" triggers for " << fParIter <<
" iterations.";
327 for (
int i = 0; i < fParIter && fDaq_loop; i++) {
329 gSystem->ProcessEvents();
338 LOG(logINFO) <<
"PixTestDaq:: start TriggerLoop with period " << finalPeriod <<
" and duration " << fParSeconds <<
" seconds";
342 uint64_t diff = 0, timepaused = 0, timeff = 0;
344 bool TotalTime =
false;
347 while (
fApi->
daqStatus(perFull) && perFull < 80 && fDaq_loop) {
348 timeff = t.get() - timepaused;
349 if (timeff / 1000 >= fParSeconds) {
354 LOG(logDEBUG) <<
"buffer not full, at " << (int)perFull <<
"%";
355 gSystem->ProcessEvents();
358 LOG(logINFO) <<
"Elapsed time: " << timeff / 1000 <<
" seconds.";
359 LOG(logINFO) <<
"Buffer almost full, pausing triggers.";
363 diff = t.get() - diff;
365 LOG(logDEBUG) <<
"Readout time: " << timepaused / 1000 <<
" seconds.";
366 LOG(logINFO) <<
"Resuming triggers for " << fParSeconds - (timeff/1000) <<
" seconds.";
370 if (TotalTime) { LOG(logINFO) <<
"PixTestDaq:: total time reached - DAQ stopped."; }
383 copy(fQ.begin(), fQ.end(), back_inserter(
fHistList));
384 copy(fQmap.begin(), fQmap.end(), back_inserter(
fHistList));
385 copy(fPh.begin(), fPh.end(), back_inserter(
fHistList));
386 copy(fPhmap.begin(), fPhmap.end(), back_inserter(
fHistList));
387 copy(fHitMap.begin(), fHitMap.end(), back_inserter(
fHistList));
400 LOG(logINFO) <<
"PixTestDaq::doDaqRun() done";
405 LOG(logINFO) <<
"PixTestDaq::doTest() start.";
406 fRunDaqTrigger =
false;
408 LOG(logINFO) <<
"PixTestDaq::doTest() done";
uint16_t prepareDaq(int triggerFreq, uint8_t trgTkDel)
set up DAQ (including call to setTriggerFrequency)
static void replaceAll(std::string &str, const std::string &from, const std::string &to)
in str, replace all occurences of from to to
size_t getNMaskedPixels(uint8_t rocid)
std::map< TH1 *, std::string > fHistOptions
options can be stored with each histogram
void daqTriggerLoopHalt()
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
std::string fStopTip
information for this test
void doTest()
function connected to "DoTest" button of PixTab
void runCommand(std::string command)
allow execution of any button in the test
std::vector< TH1 * > mapsWithString(std::vector< TH1 * >, std::string name)
return a list of TH* that have 'name' as part to their histogram name
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)
void maskHotPixels(std::vector< TH2D * >)
determine hot pixels with high occupancy
TDirectory * fDirectory
where the root histograms will end up
uint16_t daqTriggerLoop(uint16_t period=1000)
void bookTree()
book a minimal tree with pixel events
std::vector< uint8_t > getEnabledRocIDs()
void finalCleanup()
functions for DAQ
void testAllPixels(bool enable)
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
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
virtual std::string getHistOption(TH1 *)
get the hist display options (if stored in fHistOptions)
bool setTbmReg(std::string regName, uint8_t regValue, uint8_t tbmid)
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
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 update()
signal to PixTab to update the canvas
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
void setClockStretch(uint8_t src, uint16_t delay, uint16_t width)
pxar::pxarCore * fApi
pointer to the API
std::vector< Event > daqGetEventBuffer()
TProfile2D * bookTProfile2D(std::string sname, std::string title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double max, std::string option="")
book a TProfile2D, adding version information to the name and title
uint16_t daqTrigger(uint32_t nTrig=1, uint16_t period=0)
void init()
sets all test parameters
void maskPixels()
mask all pixels mentioned in the mask file
int getIdFromIdx(int idx)
provide the mapping between ROC ID and index