Commit b63f8a5f authored by Christian Bonnin's avatar Christian Bonnin
Browse files

updated Signal scan with crude clustering - to be improved

parent 0c967cb1
......@@ -522,4 +522,50 @@ namespace Ph2_HwInterface {
return os;
}
std::vector<Cluster> Event::getClusters( uint8_t pFeId, uint8_t pCbcId)
{
std::vector<Cluster> result;
// Use the bool vector method (SLOW!) TODO: improve this
std::vector<bool> stripBits = BitVector ( pFeId, pCbcId, OFFSET_CBCDATA, WIDTH_CBCDATA );
// Cluster finding
Cluster aCluster;
for (int iSensor = 0; iSensor<2; ++iSensor) {
aCluster.fSensor = iSensor;
bool inCluster = false;
for (int iStrip = iSensor; iStrip<stripBits.size(); iStrip+=2) {
if (stripBits.at(iStrip)) {
// The strip is on
if (!inCluster) {
// New cluster
aCluster.fFirstStrip = iStrip/2;
aCluster.fClusterWidth = 1;
inCluster = true;
} else {
// Increase cluster
aCluster.fClusterWidth++;
}
} else {
// The strip is off
if (inCluster) {
inCluster = false;
result.push_back(aCluster);
}
}
}
// Fix clusters at the end of the sensor
if (inCluster) result.push_back(aCluster);
}
return result;
}
double Cluster::getBaricentre() {
return fFirstStrip+double(fClusterWidth)/2.-0.5;
}
}
......@@ -29,6 +29,20 @@ namespace Ph2_HwInterface {
using FeEventMap = std::map<uint32_t, std::pair<uint32_t, uint32_t>>; /*!< Event Map of Cbc */
using EventMap = std::map<uint32_t, FeEventMap>; /*!< Event Map of FE */
/*!
* \class Cluster
* \brief Cluster object for the Event
*/
class Cluster
{
public:
uint8_t fSensor;
uint8_t fFirstStrip;
uint8_t fClusterWidth;
double getBaricentre();
};
/*!
* \class Event
* \brief Event container to manipulate event flux from the Cbc
......@@ -299,6 +313,9 @@ namespace Ph2_HwInterface {
return fEventMap;
}
friend std::ostream& operator<< ( std::ostream& out, const Event& ev );
std::vector<Cluster> getClusters( uint8_t pFeId, uint8_t pCbcId);
};
}
#endif
......@@ -20,7 +20,7 @@
<!-- Acquisition -->
<Register name="cbc_stubdata_latency_adjust_fe1">1</Register>
<Register name="cbc_stubdata_latency_adjust_fe2">1</Register>
<Register name="pc_commands.CBC_DATA_PACKET_NUMBER">9</Register>
<Register name="pc_commands.CBC_DATA_PACKET_NUMBER">99</Register>
<Register name="pc_commands.CBC_DATA_GENE">1</Register>
<Register name="pc_commands.ACQ_MODE">1</Register>
<!-- Trigger -->
......
......@@ -10,7 +10,7 @@
<Module FeId="0" FMCId="0" ModuleId="0" Status="1">
<Global_CBC_Register name="VCth"> 0x78 </Global_CBC_Register>
<Global_CBC_Register name="MiscStubLogic"> 0x5E </Global_CBC_Register>
<Global_CBC_Register name="TriggerLatency"> 0x0d </Global_CBC_Register>
<Global_CBC_Register name="TriggerLatency"> 0x0C </Global_CBC_Register>
<!-- Decoupling capacitance to VPLUS -->
<Global_CBC_Register name="MiscTestPulseCtrl&amp;AnalogMux">0x21</Global_CBC_Register>
......@@ -18,7 +18,7 @@
<!--<Global_CBC_Register name="MiscTestPulseCtrl&amp;AnalogMux">0x61</Global_CBC_Register>-->
<!--<Global_CBC_Register name="TestPulsePot">0xE0</Global_CBC_Register>-->
<CBC_Files path="./settings/"/>
<CBC_Files path="./Results/Calibration_BT_17052016/"/>
<CBC Id="0" configfile="FE0CBC0.txt"/>
<CBC Id="1" configfile="FE0CBC1.txt"/>
</Module>
......@@ -73,8 +73,8 @@
</HwDescription>
<Settings>
<Setting name="Nevents"> 3000 </Setting>
<Setting name="Nevents"> 1000 </Setting>
<Setting name="HoleMode"> 0 </Setting>
<Setting name="PedestalStepBack"> 0 </Setting>
<Setting name="SignalScanStep"> 8 </Setting>
<Setting name="PedestalStepBack"> 2 </Setting>
<Setting name="SignalScanStep"> 1 </Setting>
</Settings>
......@@ -5,16 +5,16 @@
<connection id="board" uri="chtcp-2.0://cmsuptracker008:10203?target=192.168.0.175:50001" address_table="file://settings/address_table_2CBC.xml" />
<FW_Version NCbcDataSize="4" />
<Module FeId="0" FMCId="0" ModuleId="0" Status="1">
<Global_CBC_Register name="VCth"> 0x72 </Global_CBC_Register>
<Global_CBC_Register name="VCth"> 0x76 </Global_CBC_Register>
<!--<Global_CBC_Register name="TriggerLatency"> 0x0F </Global_CBC_Register>-->
<Global_CBC_Register name="MiscTestPulseCtrl&amp;AnalogMux">0x21</Global_CBC_Register>
<!--<Global_CBC_Register name="MiscTestPulseCtrl&amp;AnalogMux">0xE1</Global_CBC_Register>-->
<!--<Global_CBC_Register name="TestPulsePot">0xE0</Global_CBC_Register>-->
<!--<Global_CBC_Register name="SelTestPulseDel&ChanGroup">0x00</Global_CBC_Register>-->
<CBC_Files path="./settings/" />
<CBC Id="0" configfile="Cbc_default_electron.txt" />
<CBC Id="1" configfile="Cbc_default_electron.txt" />
<CBC_Files path="./Results/Calibration_Electron_23-05-16_17:45/" />
<CBC Id="0" configfile="FE0CBC0.txt" />
<CBC Id="1" configfile="FE0CBC1.txt" />
<!--<CBC_Files path="./Results/Calibration_Hole_27-04-16_17:55/" />-->
<!--<CBC Id="0" configfile="FE0CBC0.txt" />-->
......@@ -59,7 +59,7 @@
</BeBoard>
</HwDescription>
<Settings>
<Setting name="Nevents"> 10 </Setting>
<Setting name="Nevents">10</Setting>
<Setting name="RunNumber">1</Setting>
<Setting name="HoleMode">0</Setting>
</Settings>
......@@ -381,7 +381,7 @@ void Commissioning::SignalScan (int SignalScanLength)
std::ofstream output;
std::string cFilename = fDirectoryName + "/SignalScanData.txt";
output.open(cFilename, std::ios::out | std::ios::app);
output << "TDC/I:nHits/I:thresh/I:dataBitString/C" << std::endl;
output << "TDC/I:nHits/I:nClusters/I:thresh/I:dataBitString/C:clusterString/C" << std::endl;
for ( auto& cBoard : fBoardVector )
{
uint32_t cBoardId = cBoard->getBeId();
......@@ -409,10 +409,10 @@ void Commissioning::SignalScan (int SignalScanLength)
// The step scan is +1 for hole mode
int cVcthDirection = ( fHoleMode == 1 ) ? +1 : -1;
//i need to read the current threshold here, save it in a variable, step back by fStepback, update the variable and then increment n times by fSignalScanStep
// I need to read the current threshold here, save it in a variable, step back by fStepback, update the variable and then increment n times by fSignalScanStep
// CBC VCth reader and writer
//this is a bit ugly but since I program the same global value to both chips I guess it is ok...
// This is a bit ugly but since I program the same global value to both chips I guess it is ok...
CbcRegReader cReader (fCbcInterface, "VCth");
this->accept(cReader);
uint8_t cVCth = cReader.fRegValue;
......@@ -423,10 +423,11 @@ void Commissioning::SignalScan (int SignalScanLength)
CbcRegWriter cWriter(fCbcInterface, "VCth", cVCth);
this->accept(cWriter);
// CbcRegIncrementer cIncrementer ( fCbcInterface, "VCth", -1 * cVcthDirection * fStepback);
// std::cout << "Stepping back " << fStepback << " from the configuration threshold" << std::endl;
// this->accept ( cIncrementer );
// cIncrementer.setRegister ("VCth", cVcthDirection * fSignalScanStep );
// Example of incrementer
// CbcRegIncrementer cIncrementer ( fCbcInterface, "VCth", -1 * cVcthDirection * fStepback);
// std::cout << "Stepping back " << fStepback << " from the configuration threshold" << std::endl;
// this->accept ( cIncrementer );
// cIncrementer.setRegister ("VCth", cVcthDirection * fSignalScanStep );
for (int i = 0; i < SignalScanLength; i += fSignalScanStep )
{
......@@ -448,15 +449,18 @@ void Commissioning::SignalScan (int SignalScanLength)
const std::vector<Event*>& events = fBeBoardInterface->GetEvents ( pBoard );
cTotalEvents += events.size();
// Loop over Events from this Acquisition
// Loop over Events from this Acquisition
for ( auto& cEvent : events )
{
for ( auto cFe : pBoard->fModuleVector )
{
TH2F* cSignalHist = static_cast<TH2F*> (getHist ( cFe, "module_signal") );
int cEventHits = 0;
int cEventClusters = 0;
std::string cDataString;
std::string cClusterDataString;
for ( auto cCbc : cFe->fCbcVector )
{
//now loop the channels for this particular event and increment a counter
......@@ -472,10 +476,25 @@ void Commissioning::SignalScan (int SignalScanLength)
//append HexDataString to cDataString
cDataString += cEvent->DataHexString(cCbc->getFeId(), cCbc->getCbcId());
cDataString += "-";
}
//this becomes an ofstream
output << +cEvent->GetTDC() << " " << cEventHits << " " << +cVCth << " " << cDataString << std::endl;
std::vector<Cluster> cClusters = cEvent->getClusters(cCbc->getFeId(), cCbc->getCbcId());
cEventClusters += cClusters.size();
cClusterDataString += "-";
for(int i = 0; i < cClusters.size(); i++){
cClusterDataString += std::to_string(cClusters[i].fFirstStrip) + "."
+ std::to_string(cClusters[i].fClusterWidth)+ "^"
+ std::to_string(cClusters[i].fSensor) + "-";
}
}
// This becomes an ofstream
output << +cEvent->GetTDC() << " "
<< cEventHits << " "
<< cEventClusters << " "
<< +cVCth << " "
<< cDataString << " "
<< cClusterDataString << std::endl;
}
}
std::cout << "Recorded " << cTotalEvents << " Events" << std::endl;
......@@ -487,7 +506,7 @@ void Commissioning::SignalScan (int SignalScanLength)
// done counting hits for all FE's, now update the Histograms
updateHists ( "module_signal", false );
//now I need to increment the threshold by cVCth+fVcthDirecton*fSignalScanStep
// now I need to increment the threshold by cVCth+fVcthDirecton*fSignalScanStep
cVCth +=cVcthDirection*fSignalScanStep;
cWriter.setRegister("VCth", cVCth);
this->accept(cWriter);
......
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