Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

70X mods to fix SiStrip Tracker PreMixing #5952

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Configuration/Applications/python/ConfigBuilder.py
Expand Up @@ -1437,6 +1437,7 @@ def prepare_DIGI2RAW(self, sequence = None):
self.scheduleSequence(sequence.split('.')[-1],'digi2raw_step')
if "DIGIPREMIX" in self.stepMap.keys():
self.executeAndRemember("process.esDigiToRaw.Label = cms.string('mix')") ##terrible hack - bypass zero suppression
self.executeAndRemember("process.SiStripDigiToRaw.FedReadoutMode = cms.string('PREMIX_RAW')") ##special readout mode for StripTracker

return

Expand Down
Expand Up @@ -107,6 +107,7 @@ namespace sistrip {
static const char fedProcRaw_[] = "FedProcessedRaw";
static const char fedZeroSuppr_[] = "FedZeroSuppressed";
static const char fedZeroSupprLite_[] = "FedZeroSupprressedLite";
static const char fedPreMixRaw_[] = "FedPreMixRaw";

// -------------------- Enumerators --------------------

Expand All @@ -123,7 +124,8 @@ namespace sistrip {
FED_VIRGIN_RAW = 2,
FED_PROC_RAW = 6,
FED_ZERO_SUPPR = 10,
FED_ZERO_SUPPR_LITE = 12
FED_ZERO_SUPPR_LITE = 12,
FED_PREMIX_RAW = 15
};

enum FedReadoutPath { UNKNOWN_FED_READOUT_PATH = sistrip::unknown_,
Expand Down
29 changes: 24 additions & 5 deletions EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h
Expand Up @@ -85,21 +85,24 @@ namespace sistrip {
public:
static FEDZSChannelUnpacker zeroSuppressedModeUnpacker(const FEDChannel& channel);
static FEDZSChannelUnpacker zeroSuppressedLiteModeUnpacker(const FEDChannel& channel);
static FEDZSChannelUnpacker preMixRawModeUnpacker(const FEDChannel& channel);
FEDZSChannelUnpacker();
uint8_t sampleNumber() const;
uint8_t adc() const;
uint16_t adcPreMix() const;
bool hasData() const;
FEDZSChannelUnpacker& operator ++ ();
FEDZSChannelUnpacker& operator ++ (int);
private:
//pointer to begining of FED or FE data, offset of start of channel payload in data and length of channel payload
FEDZSChannelUnpacker(const uint8_t* payload, const size_t channelPayloadOffset, const int16_t channelPayloadLength);
//pointer to beginning of FED or FE data, offset of start of channel payload in data and length of channel payload
FEDZSChannelUnpacker(const uint8_t* payload, const size_t channelPayloadOffset, const int16_t channelPayloadLength, const size_t offsetIncrement=1);
void readNewClusterInfo();
static void throwBadChannelLength(const uint16_t length);
void throwBadClusterLength();
static void throwUnorderedData(const uint8_t currentStrip, const uint8_t firstStripOfNewCluster);
const uint8_t* data_;
size_t currentOffset_;
size_t offsetIncrement_;
uint8_t currentStrip_;
uint8_t valuesLeftInCluster_;
uint16_t channelPayloadOffset_;
Expand Down Expand Up @@ -206,14 +209,16 @@ namespace sistrip {

inline FEDZSChannelUnpacker::FEDZSChannelUnpacker()
: data_(NULL),
offsetIncrement_(1),
valuesLeftInCluster_(0),
channelPayloadOffset_(0),
channelPayloadLength_(0)
{ }

inline FEDZSChannelUnpacker::FEDZSChannelUnpacker(const uint8_t* payload, const size_t channelPayloadOffset, const int16_t channelPayloadLength)
inline FEDZSChannelUnpacker::FEDZSChannelUnpacker(const uint8_t* payload, const size_t channelPayloadOffset, const int16_t channelPayloadLength, const size_t offsetIncrement)
: data_(payload),
currentOffset_(channelPayloadOffset),
offsetIncrement_(offsetIncrement),
currentStrip_(0),
valuesLeftInCluster_(0),
channelPayloadOffset_(channelPayloadOffset),
Expand All @@ -238,6 +243,15 @@ namespace sistrip {
return result;
}

inline FEDZSChannelUnpacker FEDZSChannelUnpacker::preMixRawModeUnpacker(const FEDChannel& channel)
{
//CAMM - to modify more ?
uint16_t length = channel.length();
if (length & 0xF000) throwBadChannelLength(length);
FEDZSChannelUnpacker result(channel.data(),channel.offset()+7,length-7,2);
return result;
}

inline uint8_t FEDZSChannelUnpacker::sampleNumber() const
{
return currentStrip_;
Expand All @@ -248,6 +262,11 @@ namespace sistrip {
return data_[currentOffset_^7];
}

inline uint16_t FEDZSChannelUnpacker::adcPreMix() const
{
return ( data_[currentOffset_^7] + ((data_[(currentOffset_+1)^7]&0x03)<<8) );
}

inline bool FEDZSChannelUnpacker::hasData() const
{
return (currentOffset_<channelPayloadOffset_+channelPayloadLength_);
Expand All @@ -257,10 +276,10 @@ namespace sistrip {
{
if (valuesLeftInCluster_) {
currentStrip_++;
currentOffset_++;
currentOffset_ += offsetIncrement_;
valuesLeftInCluster_--;
} else {
currentOffset_++;
currentOffset_ += offsetIncrement_;
if (hasData()) {
const uint8_t oldStrip = currentStrip_;
readNewClusterInfo();
Expand Down
Expand Up @@ -43,7 +43,8 @@ namespace sistrip {
READOUT_MODE_PROC_RAW=0x6,
READOUT_MODE_ZERO_SUPPRESSED=0xA,
READOUT_MODE_ZERO_SUPPRESSED_LITE=0xC,
READOUT_MODE_SPY=0xE
READOUT_MODE_SPY=0xE,
READOUT_MODE_PREMIX_RAW=0xF //0x8?
};

static const uint8_t PACKET_CODE_SCOPE = 0xE5;
Expand Down
Expand Up @@ -33,6 +33,7 @@ namespace sistrip {
uint16_t getSample(const uint16_t sampleNumber) const;
//get the 8 bit value to be used for ZS modes, converting it as the FED does if specified in constructor
uint8_t get8BitSample(const uint16_t sampleNumber) const;
uint16_t get10BitSample(const uint16_t sampleNumber) const;
void setSample(const uint16_t sampleNumber, const uint16_t adcValue);
//setting value directly is equivalent to get and set Sample but without length check
uint16_t& operator [] (const size_t sampleNumber);
Expand Down Expand Up @@ -93,8 +94,10 @@ namespace sistrip {
//fill the vector with channel data for zero suppressed modes
void fillZeroSuppressedChannelBuffer(std::vector<uint8_t>* channelBuffer, const FEDStripData::ChannelData& data, const bool channelEnabled) const;
void fillZeroSuppressedLiteChannelBuffer(std::vector<uint8_t>* channelBuffer, const FEDStripData::ChannelData& data, const bool channelEnabled) const;
//add the ZS cluster data for the channel to the end of the vector
void fillPreMixRawChannelBuffer(std::vector<uint8_t>* channelBuffer, const FEDStripData::ChannelData& data, const bool channelEnabled) const;
//add the ZS cluster data for the channel to the end of the vector
void fillClusterData(std::vector<uint8_t>* channelBuffer, const FEDStripData::ChannelData& data) const;
void fillClusterDataPreMixMode(std::vector<uint8_t>* channelBuffer, const FEDStripData::ChannelData& data) const;
std::vector<bool> feUnitsEnabled_;
std::vector<bool> channelsEnabled_;
};
Expand Down Expand Up @@ -241,6 +244,18 @@ namespace sistrip {
else return 0xFE;
}
}

inline uint16_t FEDStripData::ChannelData::get10BitSample(const uint16_t sampleNumber) const
{
if (dataIs8Bit_) {
return (0xFF & getSample(sampleNumber));
}
else {
const uint16_t sample = getSample(sampleNumber);
if (sample < 0x3FF) return sample;
else return 0x3FF;
}
}

inline std::pair<uint16_t,uint16_t> FEDStripData::ChannelData::getMedians() const
{
Expand Down
3 changes: 3 additions & 0 deletions EventFilter/SiStripRawToDigi/plugins/SiStripDigiToRaw.cc
Expand Up @@ -80,6 +80,9 @@ namespace sistrip {

auto conns = cabling->fedConnections(*ifed);

//for special mode premix raw, data is zero-suppressed but not converted to 8 bit
//zeroSuppressed here means converted to 8 bit...
if (mode_ == READOUT_MODE_PREMIX_RAW) zeroSuppressed=false;
FEDStripData fedData(zeroSuppressed);

for (auto iconn = conns.begin() ; iconn != conns.end(); iconn++ ) {
Expand Down
Expand Up @@ -34,10 +34,12 @@ namespace sistrip {
<< "[sistrip::DigiToRawModule::DigiToRawModule]"
<< " Constructing object...";
}


switch(mode_) {
case READOUT_MODE_ZERO_SUPPRESSED_LITE: rawdigi_ = false; break;
case READOUT_MODE_ZERO_SUPPRESSED: rawdigi_ = false; break;
case READOUT_MODE_PREMIX_RAW: rawdigi_ = false; break;
case READOUT_MODE_VIRGIN_RAW: rawdigi_ = true; break;
case READOUT_MODE_PROC_RAW: rawdigi_ = true; break;
case READOUT_MODE_SCOPE: rawdigi_ = true; break;
Expand Down
34 changes: 33 additions & 1 deletion EventFilter/SiStripRawToDigi/plugins/SiStripRawToDigiUnpacker.cc
Expand Up @@ -272,7 +272,7 @@ namespace sistrip {

/// unpack -> add check to make sure strip < nstrips && strip > last strip......

while (unpacker.hasData()) {zs_work_digis_.push_back(SiStripDigi(unpacker.sampleNumber()+ipair*256,unpacker.adc()));unpacker++;}
while (unpacker.hasData()) {zs_work_digis_.push_back(SiStripDigi(unpacker.sampleNumber()+ipair*256,unpacker.adc())); unpacker++;}
} catch (const cms::Exception& e) {
if ( edm::isDebugEnabled() ) {
edm::LogWarning(sistrip::mlRawToDigi_)
Expand Down Expand Up @@ -341,6 +341,38 @@ namespace sistrip {
}


}

else if (mode == sistrip::READOUT_MODE_PREMIX_RAW ) {

Registry regItem(key, 0, zs_work_digis_.size(), 0);

try {

/// create unpacker
sistrip::FEDZSChannelUnpacker unpacker = sistrip::FEDZSChannelUnpacker::preMixRawModeUnpacker(buffer->channel(iconn->fedCh()));

/// unpack -> add check to make sure strip < nstrips && strip > last strip......
while (unpacker.hasData()) {zs_work_digis_.push_back(SiStripDigi(unpacker.sampleNumber()+ipair*256,unpacker.adcPreMix()));unpacker++;}
} catch (const cms::Exception& e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we didn't do the try catch for things that wouldn't even become LogErrors.
Something to be handled in a more organized "campaign" at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. This was the original structure, though, so we just added another block of code.

if ( edm::isDebugEnabled() ) {
edm::LogWarning(sistrip::mlRawToDigi_)
<< "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
<< " Clusters are not ordered for FED "
<< *ifed << " channel " << iconn->fedCh()
<< ": " << e.what();
}
detids.push_back(iconn->detId()); //@@ Possible multiple entries (ok for Giovanni)
continue;
}

regItem.length = zs_work_digis_.size() - regItem.index;
if (regItem.length > 0) {
regItem.first = zs_work_digis_[regItem.index].strip();
zs_work_registry_.push_back(regItem);
}


}

else if ( mode == sistrip::READOUT_MODE_VIRGIN_RAW ) {
Expand Down
Expand Up @@ -172,6 +172,7 @@ sistrip::FedReadoutMode sistrip::RawToDigiUnpacker::fedReadoutMode( const uint16
else if ( ((register_value>>1)&0x7) == 0x3 ) { return sistrip::FED_PROC_RAW; }
else if ( ((register_value>>1)&0x7) == 0x5 ) { return sistrip::FED_ZERO_SUPPR; }
else if ( ((register_value>>1)&0x7) == 0x6 ) { return sistrip::FED_ZERO_SUPPR_LITE; }
else if ( ((register_value>>1)&0x7) == 0x7 ) { return sistrip::FED_PREMIX_RAW; } //new mode
else { return sistrip::UNKNOWN_FED_READOUT_MODE; }
}

Expand Down
20 changes: 11 additions & 9 deletions EventFilter/SiStripRawToDigi/src/SiStripFEDBuffer.cc
Expand Up @@ -73,15 +73,16 @@ namespace sistrip {
//set min length to 2 for ZSLite, 7 for ZS and 3 for raw
uint16_t minLength;
switch (readoutMode()) {
case READOUT_MODE_ZERO_SUPPRESSED:
minLength = 7;
break;
case READOUT_MODE_ZERO_SUPPRESSED_LITE:
minLength = 2;
break;
default:
minLength = 3;
break;
case READOUT_MODE_ZERO_SUPPRESSED:
minLength = 7;
break;
case READOUT_MODE_ZERO_SUPPRESSED_LITE:
case READOUT_MODE_PREMIX_RAW:
minLength = 2;
break;
default:
minLength = 3;
break;
}
size_t offsetBeginningOfChannel = 0;
for (size_t i = 0; i < FEDCH_PER_FED; i++) {
Expand Down Expand Up @@ -394,6 +395,7 @@ namespace sistrip {
return PACKET_CODE_ZERO_SUPPRESSED;
break;
case READOUT_MODE_ZERO_SUPPRESSED_LITE:
case READOUT_MODE_PREMIX_RAW:
case READOUT_MODE_SPY:
case READOUT_MODE_INVALID:
default:
Expand Down
15 changes: 15 additions & 0 deletions EventFilter/SiStripRawToDigi/src/SiStripFEDBufferComponents.cc
Expand Up @@ -151,6 +151,9 @@ namespace sistrip {
case READOUT_MODE_SPY:
os << "Spy channel";
break;
case READOUT_MODE_PREMIX_RAW:
os << "PreMix raw";
break;
case READOUT_MODE_INVALID:
os << "Invalid";
break;
Expand Down Expand Up @@ -364,6 +367,11 @@ namespace sistrip {
(readoutModeString == "Zero suppressed lite") ) {
return READOUT_MODE_ZERO_SUPPRESSED_LITE;
}
if ( (readoutModeString == "READOUT_MODE_PREMIX_RAW") ||
(readoutModeString == "PREMIX_RAW") ||
(readoutModeString == "PreMix Raw") ) {
return READOUT_MODE_PREMIX_RAW;
}
if ( (readoutModeString == "READOUT_MODE_SPY") ||
(readoutModeString == "SPY") ||
(readoutModeString == "Spy channel") ) {
Expand Down Expand Up @@ -650,6 +658,8 @@ namespace sistrip {
const uint8_t eventTypeNibble = trackerEventTypeNibble();
//if it is scope mode then return as is (it cannot be fake data)
if (eventTypeNibble == READOUT_MODE_SCOPE) return FEDReadoutMode(eventTypeNibble);
//if it is premix then return as is: stripping last bit would make it spy data !
if (eventTypeNibble == READOUT_MODE_PREMIX_RAW) return FEDReadoutMode(eventTypeNibble);
//if not then ignore the last bit which indicates if it is real or fake
else {
const uint8_t mode = (eventTypeNibble & 0xE);
Expand Down Expand Up @@ -735,6 +745,11 @@ namespace sistrip {
case READOUT_MODE_SPY:
setReadoutModeBits(readoutMode);
break;
case READOUT_MODE_PREMIX_RAW:
//special mode for simulation
setReadoutModeBits(readoutMode);
setDataTypeBit(true);
break;
default:
std::ostringstream ss;
ss << "Invalid readout mode: ";
Expand Down