Commit cfe7bcfc authored by Georg Auzinger's avatar Georg Auzinger
Browse files

adapted Calibration procedure to Mark's recommendation - very unstable so follow up needed

parent 93ef2a4e
......@@ -48,7 +48,7 @@ namespace Ph2_System {
if (fData) delete fData;
}
void SystemController::addFileHandler ( const std::string& pFilename , char pOption )
void SystemController::addFileHandler ( const std::string& pFilename, char pOption )
{
//if the opion is read, create a handler object and use it to read the
//file in the method below!
......@@ -209,6 +209,7 @@ namespace Ph2_System {
//reset the data object
if (fData) delete fData;
fData = new Data();
std::vector<uint32_t> cData;
//read the data and get it by reference
......
......@@ -44,7 +44,6 @@ namespace Ph2_HwInterface {
if (pType != BoardType::CBC3FC7) fNCbc = ( fEventSize - ( EVENT_HEADER_TDC_SIZE_32 ) ) / ( CBC_EVENT_SIZE_32 );
else fNCbc = (fEventSize - (EVENT_HEADER_SIZE_32_CBC3) ) / (CBC_EVENT_SIZE_32_CBC3);
// to fill fEventList
std::vector<uint32_t> lvec;
......
......@@ -71,13 +71,13 @@
</HwDescription>
<Settings>
<Setting name="TargetVcth">550</Setting>
<!--<Setting name="TargetOffset">0x50</Setting>-->
<Setting name="TargetVcth">595</Setting>
<Setting name="TargetOffset">0x50</Setting>
<!--<Setting name="TestPulsePotentiometer">0x00</Setting>-->
<Setting name="HoleMode">0</Setting>
<Setting name="VerificationLoop">1</Setting>
<!--PulseShape-->
<Setting name="Nevents" > 200 </Setting>
<Setting name="Nevents" > 100 </Setting>
<!--<Setting name="Vplus" > 0x50 </Setting>-->
<!--<Setting name="TPAmplitude" > 0x0C </Setting>-->
<!--<Setting name="TestGroup" > 1 </Setting>-->
......
......@@ -70,7 +70,7 @@ int main ( int argc, char* argv[] )
std::string cHWFile = ( cmd.foundOption ( "file" ) ) ? cmd.optionValue ( "file" ) : "settings/Calibration8CBC.xml";
std::string cDirectory = ( cmd.foundOption ( "output" ) ) ? cmd.optionValue ( "output" ) : "Results/";
cDirectory += "Calibration";
bool cVplus = ( cmd.foundOption ( "skip" ) ) ? false : true;
bool cSkip = ( cmd.foundOption ( "skip" ) ) ? true : false;
//bool cOld = ( cmd.foundOption( "old" ) ) ? true : false;
//bool cCalibrateTGrp = ( cmd.foundOption ( "allChan" ) ) ? true : false;
......@@ -106,7 +106,18 @@ int main ( int argc, char* argv[] )
//cCalibration->ConfigureHw();
cCalibration.Initialise ( false );
if ( cVplus ) cCalibration.FindVplus();
if ( !cSkip )
{
LOG (DEBUG) << "I clearly happe!";
if (cCalibration.getChipType() == ChipType::CBC2)
cCalibration.FindVplus();
else if (cCalibration.getChipType() == ChipType::CBC3)
{
cCalibration.FindTargetVcth();
LOG (DEBUG) << "Correct so far!";
}
}
cCalibration.FindOffsets();
cCalibration.SaveResults();
......
......@@ -42,6 +42,9 @@ void Calibration::Initialise ( bool pAllChan )
uint32_t cFeId = cFe->getFeId();
cFeCount++;
//figure out the chip type
fType = cFe->getChipType();
for ( auto cCbc : cFe->fCbcVector )
{
uint32_t cCbcId = cCbc->getCbcId();
......@@ -49,6 +52,14 @@ void Calibration::Initialise ( bool pAllChan )
if ( cCbcId > cCbcIdMax ) cCbcIdMax = cCbcId;
// populate the channel vector
std::vector<Channel> cChanVec;
for ( uint8_t cChan = 0; cChan < NCHANNELS; cChan++ )
cChanVec.push_back ( Channel ( cBoardId, cFeId, cCbcId, cChan ) );
fCbcChannelMap[cCbc] = cChanVec;
fVplusMap[cCbc] = 0;
TString cName = Form ( "h_VplusValues_Fe%dCbc%d", cFeId, cCbcId );
......@@ -81,6 +92,19 @@ void Calibration::Initialise ( bool pAllChan )
TH1F* cOccHist = new TH1F ( cName, Form ( "Occupancy FE%d CBC%d ; Channel; Occupancy", cFeId, cCbcId ), 254, -.5, 254.5 );
bookHistogram ( cCbc, "Occupancy", cOccHist );
//only needed for CBC3 calibration algorithm
if (fType == ChipType::CBC3)
{
cName = Form ( "h_UntunedPedestal_Fe%dCBC%d", cFeId, cCbcId );
cObj = gROOT->FindObject (cName);
if (cObj) delete cObj;
TH1F* cPedeHist = new TH1F ( cName, cName, 2048, -0.5, 1023.5 );
bookHistogram ( cCbc, "Untuned_Pedestal", cPedeHist );
}
}
}
......@@ -96,10 +120,23 @@ void Calibration::Initialise ( bool pAllChan )
LOG (INFO) << "Created Object Maps and parsed settings:" ;
LOG (INFO) << " Hole Mode = " << fHoleMode ;
if (fType != ChipType::CBC3)
{
LOG (INFO) << " Hole Mode = " << fHoleMode ;
LOG (INFO) << " TargetOffset = " << int ( fTargetOffset ) ;
LOG (INFO) << " TargetVcth = " << int ( fTargetVcth ) ;
}
else
{
LOG (INFO) << "Hole mode does not make sense for CBC3, setting to 0!";
LOG (INFO) << "TargetOffset does not make sense for CBC3, setting to 0!";
LOG (INFO) << "TargetVcth does not make sense for CBC3, should be determined algorithmically by scanning - still keeping value in case scan is skipped!";
fHoleMode = 0;
fTargetOffset = 0xFF;
}
LOG (INFO) << " Nevents = " << fEventsPerPoint ;
LOG (INFO) << " TargetVcth = " << int ( fTargetVcth ) ;
LOG (INFO) << " TargetOffset = " << int ( fTargetOffset ) ;
LOG (INFO) << " TestPulseAmplitude = " << int ( fTestPulseAmplitude ) ;
}
......@@ -150,55 +187,59 @@ void Calibration::MakeTestGroups ( bool pAllChan )
void Calibration::FindVplus()
{
// first, set VCth to the target value for each CBC
ThresholdVisitor cThresholdVisitor (fCbcInterface, fTargetVcth);
this->accept (cThresholdVisitor);
if (fType == ChipType::CBC2)
{
// first, set VCth to the target value for each CBC
ThresholdVisitor cThresholdVisitor (fCbcInterface, fTargetVcth);
this->accept (cThresholdVisitor);
// now all offsets are either off (0x00 in holes mode, 0xFF in electrons mode)
// next a group needs to be enabled - therefore now the group loop
LOG (INFO) << BOLDBLUE << "Extracting Vplus ..." << RESET ;
// now all offsets are either off (0x00 in holes mode, 0xFF in electrons mode)
// next a group needs to be enabled - therefore now the group loop
LOG (INFO) << BOLDBLUE << "Extracting Vplus ..." << RESET ;
for ( auto& cTGroup : fTestGroupChannelMap )
{
if (cTGroup.first == -1)
for ( auto& cTGroup : fTestGroupChannelMap )
{
// start with a fresh <Cbc, Vplus> map
clearVPlusMap();
if (cTGroup.first == -1)
{
// start with a fresh <Cbc, Vplus> map
clearVPlusMap();
// looping over the test groups, enable it
LOG (INFO) << GREEN << "Enabling Test Group...." << cTGroup.first << RESET ;
setOffset ( fTargetOffset, cTGroup.first, true ); // takes the group ID
//updateHists ( "Offsets" );
// looping over the test groups, enable it
LOG (INFO) << GREEN << "Enabling Test Group...." << cTGroup.first << RESET ;
setOffset ( fTargetOffset, cTGroup.first, true ); // takes the group ID
//updateHists ( "Offsets" );
bitwiseVplus ( cTGroup.first );
bitwiseVplus ( cTGroup.first );
LOG (INFO) << RED << "Disabling Test Group...." << cTGroup.first << RESET ;
uint8_t cOffset = ( fHoleMode ) ? 0x00 : 0xFF;
setOffset ( cOffset, cTGroup.first, true );
LOG (INFO) << RED << "Disabling Test Group...." << cTGroup.first << RESET ;
uint8_t cOffset = ( fHoleMode ) ? 0x00 : 0xFF;
setOffset ( cOffset, cTGroup.first, true );
// done looping all the bits - I should now have the Vplus value that corresponds to 50% occupancy at the desired VCth and Offset for this test group mapped against CBC
for ( auto& cCbc : fVplusMap )
{
TProfile* cTmpProfile = static_cast<TProfile*> ( getHist ( cCbc.first, "Vplus" ) );
cTmpProfile->Fill ( cTGroup.first, cCbc.second ); // fill Vplus value for each test group
}
// done looping all the bits - I should now have the Vplus value that corresponds to 50% occupancy at the desired VCth and Offset for this test group mapped against CBC
for ( auto& cCbc : fVplusMap )
{
TProfile* cTmpProfile = static_cast<TProfile*> ( getHist ( cCbc.first, "Vplus" ) );
cTmpProfile->Fill ( cTGroup.first, cCbc.second ); // fill Vplus value for each test group
}
//updateHists ( "Vplus" );
//
//updateHists ( "Vplus" );
//
}
}
}
// done extracting reasonable Vplus values for all test groups, now find the mean
// since I am lazy and do not want to iterate all boards, FEs etc, i Iterate fVplusMap
for ( auto& cCbc : fVplusMap ) //this toggles bit i on Vplus for each
{
TProfile* cTmpProfile = static_cast<TProfile*> ( getHist ( cCbc.first, "Vplus" ) );
cCbc.second = cTmpProfile->GetMean ( 2 );
// done extracting reasonable Vplus values for all test groups, now find the mean
// since I am lazy and do not want to iterate all boards, FEs etc, i Iterate fVplusMap
for ( auto& cCbc : fVplusMap ) //this toggles bit i on Vplus for each
{
TProfile* cTmpProfile = static_cast<TProfile*> ( getHist ( cCbc.first, "Vplus" ) );
cCbc.second = cTmpProfile->GetMean ( 2 );
fCbcInterface->WriteCbcReg ( cCbc.first, "Vplus", cCbc.second );
LOG (INFO) << BOLDGREEN << "Mean Vplus value for FE " << +cCbc.first->getFeId() << " CBC " << +cCbc.first->getCbcId() << " is " << BOLDRED << +cCbc.second << RESET ;
}
fCbcInterface->WriteCbcReg ( cCbc.first, "Vplus", cCbc.second );
LOG (INFO) << BOLDGREEN << "Mean Vplus value for FE " << +cCbc.first->getFeId() << " CBC " << +cCbc.first->getCbcId() << " is " << BOLDRED << +cCbc.second << RESET ;
}
}
else LOG (INFO) << "VPlus measurement does not make sense for CBC3, doing nothing!";
}
void Calibration::bitwiseVplus ( int pTGroup )
......@@ -257,6 +298,89 @@ void Calibration::bitwiseVplus ( int pTGroup )
}
}
float Calibration::FindTargetVcth()
{
if (fType == ChipType::CBC3)
{
TCanvas* cCanvas = new TCanvas ( "Untuned Pedestals", "Untuned Pedestal", 425, 10, 500, 500 );
cCanvas->DivideSquare (fNCbc);
LOG (INFO) << BOLDGREEN << "Measuring Untuned SCurve midpoints..." << RESET;
uint8_t cOffset = 0xFF;
LOG (INFO) << "Disabling all TestGroups by setting all channel offsets to " << std::hex << "0x" << +cOffset << std::dec;
//disable all test groups
auto cGroup = fTestGroupChannelMap.find (-1);
if (cGroup != std::end (fTestGroupChannelMap) )
setOffset (cOffset, cGroup->first, false);
else LOG (ERROR) << "Test Group not found!";
updateHists ( "Offsets" );
//loop the test groups, enable a group, measure an SCurve
for (auto& cTGrp : fTestGroupChannelMap)
{
if (cTGrp.first != -1)
{
setOffset ( 0x80, cTGrp.first, true ); // takes the group ID
updateHists ( "Offsets" );
initializeSCurves ("Offset", 0x80, cTGrp.first);
measureSCurves (cTGrp.first, 450);
setOffset (cOffset, cTGrp.first, true);
updateHists ( "Offsets" );
}
}
//process the SCurves and fill in the pedestal Histogram
float cMeanPedestal = 0;
int iCbc = 1;
for ( auto& cCbc : fCbcChannelMap )
{
TH1F* cPedeHist = dynamic_cast<TH1F*> ( getHist ( cCbc.first, "Untuned_Pedestal" ) );
//std::vector<uint8_t> cTestGrpChannelVec = fTestGroupChannelMap[pTGrp];
for (uint8_t cChanId = 0; cChanId < NCHANNELS; cChanId++)
//for ( auto& cChanId : cTestGrpChannelVec )
{
//for ( auto& cChan : cCbc.second )
Channel cChan = cCbc.second.at ( cChanId );
// Fit or Differentiate
//if ( fFitted ) cChan.fitHist ( fEventsPerPoint, fHoleMode, pValue, pParameter, fResultFile );
cChan.differentiateHist ( fEventsPerPoint, fHoleMode, 0, "Untuned", fResultFile );
// instead of the code below, use a histogram to histogram the noise
if ( cChan.getNoise() == 0 || cChan.getNoise() > 1023 ) LOG (INFO) << RED << "Error, SCurve Fit for Fe " << int ( cCbc.first->getFeId() ) << " Cbc " << int ( cCbc.first->getCbcId() ) << " Channel " << int ( cChan.fChannelId ) << " did not work correctly! Noise " << cChan.getNoise() << RESET ;
cPedeHist->Fill ( cChan.getPedestal() );
}
cMeanPedestal += cPedeHist->GetMean();
LOG (INFO) << BOLDRED << "Average untuned pedestal for Fe " << +cCbc.first->getFeId() << " Cbc " << +cCbc.first->getCbcId() << " : " << cPedeHist->GetMean() << " Vcth units!" << RESET;
cCanvas->cd (iCbc);
cPedeHist->Draw ("APL");
iCbc++;
}
fTargetVcth = static_cast<uint16_t> (cMeanPedestal / fNCbc);
LOG (INFO) << BOLDCYAN << "Setting target Vcth to " << fTargetVcth << RESET;
return cMeanPedestal / fNCbc;
}
else
{
LOG (INFO) << "This measurement does not make sense for CBC2, doing nothing!";
return 0;
}
}
void Calibration::FindOffsets()
{
// do a binary search for the correct offset value
......
......@@ -12,8 +12,9 @@
#ifndef Calibration_h__
#define Calibration_h__
#include "Tool.h"
#include "Channel.h"
//#include "Tool.h"
//#include "Channel.h"
#include "SCurve.h"
#include "../Utils/Visitor.h"
#include "../Utils/CommonVisitors.h"
......@@ -33,16 +34,19 @@ using namespace Ph2_System;
// Typedefs for Containers
typedef std::map<Cbc*, std::vector<Channel> > CbcChannelMap;
//typedef std::map<Cbc*, std::vector<Channel> > CbcChannelMap;
// typedef std::map<Cbc*, TF1*> FitMap;
// typedef std::map<Cbc*, TH1F*> HistMap;
typedef std::vector<std::pair< std::string, uint8_t> > RegisterVector;
typedef std::map< int, std::vector<uint8_t> > TestGroupChannelMap;
//typedef std::vector<std::pair< std::string, uint8_t> > RegisterVector;
//typedef std::map< int, std::vector<uint8_t> > TestGroupChannelMap;
class Calibration : public Tool
//class Calibration : public Tool
class Calibration : public SCurve
{
public:
Calibration() {};
Calibration()
{
};
~Calibration()
{
//if ( fResultFile ) {
......@@ -53,6 +57,7 @@ class Calibration : public Tool
void Initialise ( bool pAllChan = false );
void FindVplus();
float FindTargetVcth();
// offsets are found by taking pMultiple*fEvents triggers
void FindOffsets();
void SaveResults()
......@@ -61,6 +66,10 @@ class Calibration : public Tool
//dumpConfigFiles();
}
ChipType getChipType()
{
return fType;
}
protected:
void MakeTestGroups ( bool pAllChan = false );
......@@ -90,6 +99,7 @@ class Calibration : public Tool
void writeGraphs();
private:
// helper methods
void setRegBit ( uint8_t& pRegValue, uint8_t pPos, bool pValue )
......@@ -113,21 +123,22 @@ class Calibration : public Tool
TCanvas* fOccupancyCanvas;
// Containers
TestGroupChannelMap fTestGroupChannelMap;
//TestGroupChannelMap fTestGroupChannelMap;
std::map<Cbc*, uint8_t> fVplusMap;
// Counters
uint32_t fNCbc;
uint32_t fNFe;
//uint32_t fNCbc;
//uint32_t fNFe;
// Settings
bool fHoleMode;
bool fTestPulse;
uint8_t fTestPulseAmplitude;
uint32_t fEventsPerPoint;
//bool fHoleMode;
//bool fTestPulse;
//uint8_t fTestPulseAmplitude;
//uint32_t fEventsPerPoint;
uint16_t fTargetVcth;
uint8_t fTargetOffset;
bool fCheckLoop;
//ChipType fChipType;
};
......
......@@ -67,11 +67,11 @@ void SCurve::setOffset ( uint8_t pOffset, int pGroup )
}
void SCurve::measureSCurves ( int pTGrpId )
void SCurve::measureSCurves ( int pTGrpId, uint16_t pStartValue )
{
// Adaptive Loop to measure SCurves
LOG (INFO) << BOLDGREEN << "Measuring SCurves sweeping VCth ... " << RESET << std::endl;
LOG (INFO) << BOLDGREEN << "Measuring SCurves sweeping VCth ... " << RESET;
// Necessary variables
bool cNonZero = false;
......@@ -99,7 +99,7 @@ void SCurve::measureSCurves ( int pTGrpId )
}
else
{
cValue = 0x00;
cValue = pStartValue;
cStep = 10;
}
......@@ -131,6 +131,7 @@ void SCurve::measureSCurves ( int pTGrpId )
// DEBUG
if ( cAllOne ) break;
for ( BeBoard* pBoard : fBoardVector )
{
for (Module* cFe : pBoard->fModuleVector)
......@@ -150,6 +151,7 @@ void SCurve::measureSCurves ( int pTGrpId )
cN++;
}
cNthAcq++;
Counter cCounter;
pBoard->accept ( cCounter );
......
......@@ -76,7 +76,7 @@ class SCurve : public Tool
void setOffset ( uint8_t pOffset, int pGroup );
// SCurve related
void measureSCurves ( int pTGrpId );
void measureSCurves ( int pTGrpId, uint16_t pStartValue = 0x00 );
void measureSCurvesOffset ( int pTGrpId );
uint32_t fillSCurves ( BeBoard* pBoard, const Event* pEvent, uint16_t pValue, int pTGrpId, bool pDraw = false );
void initializeSCurves ( TString pParameter, uint16_t pValue, int pTGrpId );
......
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