Commit 7021e54f authored by Georg Auzinger's avatar Georg Auzinger
Browse files

inserted final version of mytool class and mytest executable as coded at the workshop

parent 4ed74b8e
......@@ -16,7 +16,7 @@ LibraryDirs = $(BOOST_LIB) ../lib
IncludeDirs = $(BOOST_INCLUDE) ../ ../HWInterface ../System ../Utils ../tools
ExternalObjects= -lboost_system -lboost_thread -lcactus_uhal_uhal -lcactus_extern_pugixml -lcactus_uhal_log -lcactus_uhal_grammars -lPh2_Utils -lPh2_Description -lPh2_Interface -lPh2_System -lPh2_Tools
binaries=print systemtest datatest calibrate commission fpgaconfig
binaries=print systemtest datatest calibrate commission fpgaconfig mytest
##################################################
## check if the Root has THttp
......
......@@ -70,6 +70,11 @@ int main ( int argc, char* argv[] )
t.start();
//HW configured according to config file, everything ready for us to take over!
//her goes our code
//the constructor with channel number and test group
mytool cMyTool (0, 0);
cMyTool.Inherit (&cTool);
cMyTool.Initialize();
cMyTool.SweepTPDelay();
t.stop();
t.show ( "Time to run our code: " );
......
......@@ -7,7 +7,7 @@ CC = g++
CXX = g++
CCFlags = -g -O1 -w -Wall -pedantic -pthread -fPIC `root-config --cflags --evelibs`
Objs = Tool.o Calibration.o Channel.o LatencyScan.o SignalScan.o PedeNoise.o
Objs = Tool.o Calibration.o Channel.o LatencyScan.o SignalScan.o PedeNoise.o mytool.o
ROOTVERSION := $(shell root-config --has-http)
RootLibraryDirs = $(ROOTLIB)
......
#include "mytool.h"
///////////////////////////
//Here goes our code
///////////////////////////
mytool::mytool (uint8_t pChannel, uint8_t pTestGroup) :
fChan (pChannel),
fTestGroup (pTestGroup)
{
}
void mytool::Initialize()
{
//let's start by parsing the settings
this->parseSettings();
//we want to keep things simple, so lets get a pointer to a CBC and a pointer to a BeBoard
//this will facilitate the code as we save a lot of looping
fBoard = this->fBoardVector.at (0);
fCbc = fBoard->fModuleVector.at (0)->fCbcVector.at (0);
//we also need a TCanvas
fCanvas = new TCanvas ("mytool", "mytool");
fCanvas->Divide (2, 1);
//and construct our pulseshape histogram
fPulse = new TH1F ("pulseshape", "pulseshape; Time [ns]; SCurve Midpoint [VCth]", 40, 0, 200);
//now let's enable exactly 1 channel by setting the offset to 80 decimal in electron mode or 170 in hole mode
//the channel registers in the CBC file start from 1, our channels start from 0
this->fCbcInterface->WriteCbcReg (fCbc, Form ("Channel%03d", fChan + 1), (fHoleMode) ? 0xaa : 0x50 );
LOG (INFO) << "Enabled channel " << +fChan << " by setting offset to 80";
fChannel = new Channel (fBoard->getBeId(), fCbc->getFeId(), fCbc->getCbcId(), fChan );
fChannel->initializeHist (0, "VCth");
}
void mytool::SweepTPDelay()
{
LOG (INFO) << "Start sweeping delays";
//first, set up the CbcTestPulse
this->setSystemTestPulse (fTPAmplitude, fTestGroup, true, fHoleMode );
//now, lets figure out the time window we want to sweep
//default timing is: trigger 200 clock cycles after test pulse
//therefore we probably want to loop from 0 clock cycles relative to that to +8 clock cycles
//this corresponds to a time window of 200ns in steps of 5ns makes 40 bins
int cCoarseDefault = 200;
int cLow = ( cCoarseDefault - 0 ) * 25;
int cHigh = ( cCoarseDefault + 8 ) * 25;
int cSteps = 5;
int cBin = 1;
///////////////////////////
//HELPER FUNCTIONS KINDLY PROVIDED
///////////////////////////
//loop
for (uint32_t cDelayns = cLow; cDelayns < cHigh; cDelayns += cSteps)
{
//set the delays
setDelayAndTestGroup (cDelayns);
LOG (INFO) << "Setting delay to " << cDelayns << " ns and filling bin " << cBin;
//measure the pedestal
double cPedestal = this->measureSCurve();
//fill our pulse shape histogram
fPulse->SetBinContent (cBin, cPedestal);
//draw it
fCanvas->cd (2);
fPulse->Draw();
fCanvas->Update();
cBin++;
}
LOG (INFO) << "Finished sweeping delays";
}
double mytool::measureSCurve()
{
fChannel->resetHist();
//loop the threshold
for (uint8_t cVcth = 0; cVcth < 254; cVcth += 1)
{
//set the threshold
this->fCbcInterface->WriteCbcReg (fCbc, "VCth", cVcth);
//now read 20 Events
this->ReadNEvents (fBoard, fNevents);
const std::vector<Event*> cEvents = this->GetEvents (fBoard);
//now loop the events and fill the histogram
uint32_t cHitCounter = 0;
for (auto cEvent : cEvents)
{
//if our channel fChan is hit, fill the histogram for channel
if (cEvent->DataBit (fCbc->getFeId(), fCbc->getCbcId(), fChan) )
{
cHitCounter++;
fChannel->fillHist (cVcth);
}
}
//if (cHitCounter == fNevents) break;
LOG (INFO) << "Measured " << cHitCounter << " hits in " << fNevents << " Events for VCth " << +cVcth;
}
//ok, now here we have a complete SCurve histogram from 0 to 255
//differentiate it and return the pedestal
fCanvas->cd (1);
fChannel->fScurve->Draw ("PX0");
fChannel->differentiateHist (fNevents, fHoleMode, 0, "VCth", nullptr);
double cPedestal = fChannel->getPedestal();
LOG (INFO) << "Found SCurve midpoint at " << cPedestal;
return cPedestal;
}
void mytool::setDelayAndTestGroup ( uint32_t pDelayns )
{
......
......@@ -22,10 +22,10 @@ class mytool : public Tool
~mytool() {}
void Initialize();
double measureSCurve ();
void SweepTPDelay();
private:
double measureSCurve ();
void setDelayAndTestGroup ( uint32_t pDelayns );
void parseSettings();
......
Supports Markdown
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