Skip to content

Commit

Permalink
use flavor 7 w/ type 15 for premixed MC packing/unpacking of QIE8 w/ …
Browse files Browse the repository at this point in the history
…uHTR (preserve error bits)
  • Loading branch information
kpedro88 committed May 31, 2017
1 parent eaaa3e3 commit 0bf96d3
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
ecalPacker.InstanceEE = 'eeDigis'
ecalPacker.labelEBSRFlags = "simEcalDigis:ebSrFlags"
ecalPacker.labelEESRFlags = "simEcalDigis:eeSrFlags"
hcalRawDatauHTR.premix = cms.bool(True)

from Configuration.Eras.Modifier_phase2_common_cff import phase2_common
phase2_common.toReplaceWith(DigiToRaw, DigiToRaw.copyAndExclude([castorRawData]))
Expand Down
15 changes: 9 additions & 6 deletions EventFilter/HcalRawToDigi/interface/HcalUHTRData.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ class HcalUHTRData {
public:
const_iterator(const uint16_t* ptr, const uint16_t* limit=0);

bool isHeader() const { return ((*m_ptr)&0x8000)!=0; }
int flavor() const { return ((*m_ptr)>>12)&0x7; }
int errFlags() const { return ((*m_ptr)>>10)&0x3; }
int capid0() const { return ((*m_ptr)>>8)&0x3; }
int channelid() const { return ((*m_ptr))&0xFF; }
bool isHeader() const { return ((*m_ptr)&0x8000)!=0; }
int flavor() const { return ((*m_ptr)>>12)&0x7; }
int errFlags() const;
bool dataValid() const;
int capid0() const { return ((*m_ptr)>>8)&0x3; }
int channelid() const { return ((*m_ptr))&0xFF; }
int technicalDataType() const;

uint16_t value() const { return *m_ptr; }

Expand All @@ -72,7 +74,8 @@ class HcalUHTRData {
int m_microstep;
int m_stepclass;
int m_flavor;
};
int m_technicalDataType;
};

const_iterator begin() const;
const_iterator end() const;
Expand Down
9 changes: 6 additions & 3 deletions EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class HcalDigiToRawuHTR : public edm::stream::EDProducer<> {
edm::Handle<HcalTrigPrimDigiCollection> tpDigiCollection;

edm::InputTag qie10Tag_, qie11Tag_, hbheqie8Tag_, hfqie8Tag_, trigTag_;
bool premix_;
};

HcalDigiToRawuHTR::HcalDigiToRawuHTR(const edm::ParameterSet& iConfig) :
Expand All @@ -73,7 +74,8 @@ HcalDigiToRawuHTR::HcalDigiToRawuHTR(const edm::ParameterSet& iConfig) :
qie11Tag_(iConfig.getParameter<edm::InputTag>("QIE11")),
hbheqie8Tag_(iConfig.getParameter<edm::InputTag>("HBHEqie8")),
hfqie8Tag_(iConfig.getParameter<edm::InputTag>("HFqie8")),
trigTag_(iConfig.getParameter<edm::InputTag>("TP"))
trigTag_(iConfig.getParameter<edm::InputTag>("TP")),
premix_(iConfig.getParameter<bool>("premix"))
{
produces<FEDRawDataCollection>("");
tok_QIE10DigiCollection_ = consumes<HcalDataFrameContainer<QIE10DataFrame> >(qie10Tag_);
Expand Down Expand Up @@ -174,7 +176,7 @@ void HcalDigiToRawuHTR::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
if( ! uhtrs.exist(uhtrIndex) ){
uhtrs.newUHTR( uhtrIndex , presamples );
}
uhtrs.addChannel(uhtrIndex,qiedf,readoutMap,_verbosity);
uhtrs.addChannel(uhtrIndex,qiedf,readoutMap,premix_,_verbosity);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand All @@ -195,7 +197,7 @@ void HcalDigiToRawuHTR::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
if( ! uhtrs.exist(uhtrIndex) ){
uhtrs.newUHTR( uhtrIndex , presamples );
}
uhtrs.addChannel(uhtrIndex,qiedf,readoutMap,_verbosity);
uhtrs.addChannel(uhtrIndex,qiedf,readoutMap,premix_,_verbosity);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -280,6 +282,7 @@ void HcalDigiToRawuHTR::fillDescriptions(edm::ConfigurationDescriptions& descrip
desc.add<edm::InputTag>("HBHEqie8", edm::InputTag("simHcalDigis"));
desc.add<edm::InputTag>("HFqie8", edm::InputTag("simHcalDigis"));
desc.add<edm::InputTag>("TP", edm::InputTag("simHcalTriggerPrimitiveDigis"));
desc.add<bool>("premix", false);
descriptions.add("hcalDigiToRawuHTR",desc);
descriptions.addDefault(desc);
}
Expand Down
95 changes: 72 additions & 23 deletions EventFilter/HcalRawToDigi/plugins/PackerHelp.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ namespace QIE8HeaderSpec{
static const int MASK_FLAVOR = 0x7;
static const int OFFSET_HEADER_BIT = 15;
static const int MASK_HEADER_BIT = 0x1;
static const int OFFSET_TECHNICAL_DATA_TYPE = 8;
static const int MASK_TECHNICAL_DATA_TYPE = 0xF;
}

namespace QIE10HeaderSpec{
Expand Down Expand Up @@ -144,6 +146,17 @@ namespace TPHeaderSpec{
static const int MASK_HEADER_BIT = 0x1;
}

namespace QIE8SampleSpec{
static const int OFFSET_ADC = 0;
static const int MASK_ADC = 0x7F;
static const int OFFSET_CAPID = 8;
static const int MASK_CAPID = 0x3;
static const int OFFSET_DV = 10;
static const int MASK_DV = 0x1;
static const int OFFSET_ER = 11;
static const int MASK_ER = 0x1;
}

class HCalFED{

public:
Expand Down Expand Up @@ -331,7 +344,8 @@ class UHTRpacker{
return uhtrs.count(uhtrIndex) != 0 ;
};

uint16_t packQIE8header(const HcalQIESample &qieSample, const HcalElectronicsId &eid){
// flavor should be 5, or 7 (only for premixing in sim)
uint16_t packQIE8header(const HcalQIESample &qieSample, const HcalElectronicsId &eid, int flavor){
uint16_t header =0;

int fiber = eid.fiberIndex()+1;
Expand All @@ -341,14 +355,35 @@ class UHTRpacker{

header |= (fiberchan & QIE8HeaderSpec::MASK_FIBERCHAN)<<QIE8HeaderSpec::OFFSET_FIBERCHAN;
header |= ((fiber-1) & QIE8HeaderSpec::MASK_FIBER)<<QIE8HeaderSpec::OFFSET_FIBER;
header |= (capid0 & QIE8HeaderSpec::MASK_CAPID)<<QIE8HeaderSpec::OFFSET_CAPID;
header |= (fiberErr & QIE8HeaderSpec::MASK_FIBERERR)<<QIE8HeaderSpec::OFFSET_FIBERERR;
header |= (0x5 & QIE8HeaderSpec::MASK_FLAVOR)<<QIE8HeaderSpec::OFFSET_FLAVOR; //flavor
if(flavor==7){
header |= (15 & QIE8HeaderSpec::MASK_TECHNICAL_DATA_TYPE)<<QIE8HeaderSpec::OFFSET_TECHNICAL_DATA_TYPE;
}
else {
header |= (capid0 & QIE8HeaderSpec::MASK_CAPID)<<QIE8HeaderSpec::OFFSET_CAPID;
header |= (fiberErr & QIE8HeaderSpec::MASK_FIBERERR)<<QIE8HeaderSpec::OFFSET_FIBERERR;
}
header |= (flavor & QIE8HeaderSpec::MASK_FLAVOR)<<QIE8HeaderSpec::OFFSET_FLAVOR; //flavor
header |= (0x1 & QIE8HeaderSpec::MASK_HEADER_BIT)<<QIE8HeaderSpec::OFFSET_HEADER_BIT;

return header;
}

uint16_t packQIE8sample(const HcalQIESample &qieSample){
uint16_t sample = 0;

int adc = qieSample.adc();
int capid = qieSample.capid();
int dv = qieSample.dv();
int er = qieSample.er();

sample |= (adc & QIE8SampleSpec::MASK_ADC)<<QIE8SampleSpec::OFFSET_ADC;
sample |= (capid & QIE8SampleSpec::MASK_CAPID)<<QIE8SampleSpec::OFFSET_CAPID;
sample |= (dv & QIE8SampleSpec::MASK_DV)<<QIE8SampleSpec::OFFSET_DV;
sample |= (er & QIE8SampleSpec::MASK_ER)<<QIE8SampleSpec::OFFSET_ER;

return sample;
}

uint16_t packTPheader(const HcalTriggerPrimitiveSample &tpSample, int channelid){
uint16_t header =0;

Expand Down Expand Up @@ -459,37 +494,51 @@ class UHTRpacker{
uhtr->push_back( 0 );
};

void addChannel( int uhtrIndex , edm::SortedCollection<HFDataFrame>::const_iterator& qiedf , const HcalElectronicsMap* readoutMap, int verbosity = 0 ){
void addChannel( int uhtrIndex , edm::SortedCollection<HFDataFrame>::const_iterator& qiedf , const HcalElectronicsMap* readoutMap, bool premix, int verbosity = 0 ){
if( qiedf->size() == 0 ) return;
DetId detid = qiedf->id();
HcalElectronicsId eid(readoutMap->lookup(detid));
uint16_t header = packQIE8header(qiedf->sample(0), eid);
uint16_t header = packQIE8header(qiedf->sample(0), eid, premix ? 7 : 5);
uhtrs[uhtrIndex].push_back(header);
// loop over words in dataframe
for(int iTS = 0; iTS < qiedf->size(); iTS +=2 ){
uint16_t cont =0;
int adc0 = qiedf->sample(iTS).adc();
int adc1 = qiedf->sample(iTS+1).adc();
cont |= adc0&0xFF;
cont |= (adc1&0xFF)<<8;
uhtrs[uhtrIndex].push_back(cont);
if(premix){
for(int iTS = 0; iTS < qiedf->size(); ++iTS){
uhtrs[uhtrIndex].push_back(packQIE8sample(qiedf->sample(iTS)));
}
}
else {
for(int iTS = 0; iTS < qiedf->size(); iTS +=2 ){
uint16_t cont =0;
int adc0 = qiedf->sample(iTS).adc();
int adc1 = qiedf->sample(iTS+1).adc();
cont |= adc0&0xFF;
cont |= (adc1&0xFF)<<8;
uhtrs[uhtrIndex].push_back(cont);
}
}// end loop over dataframe words
};

void addChannel( int uhtrIndex , edm::SortedCollection<HBHEDataFrame>::const_iterator qiedf , const HcalElectronicsMap* readoutMap, int verbosity = 0 ){
void addChannel( int uhtrIndex , edm::SortedCollection<HBHEDataFrame>::const_iterator qiedf , const HcalElectronicsMap* readoutMap, bool premix, int verbosity = 0 ){
if( qiedf->size() == 0 ) return;
DetId detid = qiedf->id();
HcalElectronicsId eid(readoutMap->lookup(detid));
uint16_t header = packQIE8header(qiedf->sample(0), eid);
uint16_t header = packQIE8header(qiedf->sample(0), eid, premix ? 7 : 5);
uhtrs[uhtrIndex].push_back(header);
// loop over words in dataframe
for(int iTS = 0; iTS < qiedf->size(); iTS +=2 ){
uint16_t cont =0;
int adc0 = qiedf->sample(iTS).adc();
int adc1 = qiedf->sample(iTS+1).adc();
cont |= adc0&0xFF;
cont |= (adc1&0xFF)<<8;
uhtrs[uhtrIndex].push_back(cont);
if(premix){
for(int iTS = 0; iTS < qiedf->size(); ++iTS){
uhtrs[uhtrIndex].push_back(packQIE8sample(qiedf->sample(iTS)));
}
}
else {
for(int iTS = 0; iTS < qiedf->size(); iTS +=2 ){
uint16_t cont =0;
int adc0 = qiedf->sample(iTS).adc();
int adc1 = qiedf->sample(iTS+1).adc();
cont |= adc0&0xFF;
cont |= (adc1&0xFF)<<8;
uhtrs[uhtrIndex].push_back(cont);
}
}// end loop over dataframe words
};

Expand All @@ -508,7 +557,7 @@ class UHTRpacker{
DetId detid = qiedf.detid();
HcalElectronicsId eid(readoutMap->lookup(detid));
// loop over words in dataframe
for(edm::DataFrame::iterator dfi=qiedf.begin() ; dfi!=qiedf.end(); ++dfi){
for(edm::DataFrame::iterator dfi=qiedf.begin() ; dfi!=qiedf.end(); ++dfi){
if( dfi >= qiedf.end()-QIE11DataFrame::FLAG_WORDS ){
continue;
}
Expand Down
30 changes: 26 additions & 4 deletions EventFilter/HcalRawToDigi/src/HcalUHTRData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

static const int HEADER_LENGTH_16BIT=2*sizeof(uint64_t)/sizeof(uint16_t);

HcalUHTRData::const_iterator::const_iterator(const uint16_t* ptr, const uint16_t* limit) : m_ptr(ptr), m_limit(limit), m_stepclass(0) {
HcalUHTRData::const_iterator::const_iterator(const uint16_t* ptr, const uint16_t* limit) :
m_ptr(ptr), m_limit(limit), m_stepclass(0), m_technicalDataType(0)
{
if (isHeader()) determineMode();
}

Expand Down Expand Up @@ -33,21 +35,38 @@ void HcalUHTRData::const_iterator::determineMode() {
m_stepclass=0;
if (m_flavor==5) { m_stepclass=1; m_microstep=0; }
else if (m_flavor == 2) { m_stepclass=2; }
if (m_flavor==7) { m_technicalDataType = technicalDataType(); }
}

int HcalUHTRData::const_iterator::errFlags() const {
if ((m_flavor==7 && m_technicalDataType==15) && !isHeader()) return ((*m_ptr)>>11)&0x1;
else return ((*m_ptr)>>10)&0x3;
}

bool HcalUHTRData::const_iterator::dataValid() const {
if ((m_flavor==7 && m_technicalDataType==15) && !isHeader()) return ((*m_ptr)>>10)&0x1;
else return !(errFlags()&0x2);
}

int HcalUHTRData::const_iterator::technicalDataType() const {
if (m_flavor==7) return ((*m_ptr)>>8)&0xF;
else return 0;
}

uint8_t HcalUHTRData::const_iterator::adc() const {
if (m_flavor==0x5 && m_microstep==0) return ((*m_ptr)>>8)&0x7F;
if (m_flavor==5 && m_microstep==0) return ((*m_ptr)>>8)&0x7F;
else if (m_flavor==7 && m_technicalDataType==15) return (*m_ptr)&0x7F;
else return (*m_ptr)&0xFF;
}

uint8_t HcalUHTRData::const_iterator::le_tdc() const {
if (m_flavor==0x5) return 0x80;
if (m_flavor==5 || (m_flavor==7 && m_technicalDataType==15)) return 0x80;
else if (m_flavor == 2) return (m_ptr[1]&0x3F);
else return (((*m_ptr)&0x3F00)>>8);
}

bool HcalUHTRData::const_iterator::soi() const {
if (m_flavor==0x5) return false;
if (m_flavor==5 || (m_flavor==7 && m_technicalDataType==15)) return false;
else if (m_flavor == 2) return (m_ptr[0]&0x2000);
else return (((*m_ptr)&0x4000));
}
Expand All @@ -59,6 +78,9 @@ uint8_t HcalUHTRData::const_iterator::te_tdc() const {

uint8_t HcalUHTRData::const_iterator::capid() const {
if (m_flavor==2) return(m_ptr[1]>>12)&0x3;
else if (m_flavor==7 && m_technicalDataType==15) {
return ((*m_ptr)>>8)&0x3;
}
else if (m_flavor == 1 || m_flavor == 0) {
// For flavor 0,1 we only get the first capid in the header, and so we need
// to count the number of data rows and figure out which cap we want,
Expand Down
33 changes: 24 additions & 9 deletions EventFilter/HcalRawToDigi/src/HcalUnpacker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ namespace HcalUnpacker_impl {
digi.setReadoutIds(eid);
int error_flags=i.errFlags();
int capid0=i.capid0();
int flavor = i.flavor();

bool isCapRotating=!(error_flags&0x1);
bool fiberErr=(error_flags&0x2);
Expand All @@ -134,19 +135,33 @@ namespace HcalUnpacker_impl {

// what is my sample number?
int ncurr=0,ntaken=0;
for (++i; i!=iend && !i.isHeader(); ++i) {
int capidn=(isCapRotating)?((capid0+ncurr)%4):(capid0);
if(flavor==5){
for (++i; i!=iend && !i.isHeader(); ++i) {
int capidn=(isCapRotating)?((capid0+ncurr)%4):(capid0);

HcalQIESample s(i.adc(),capidn,fiber,fiberchan,dataValid,fiberErr);
HcalQIESample s(i.adc(),capidn,fiber,fiberchan,dataValid,fiberErr);

if (ncurr>=startSample && ncurr<=endSample) {
digi.setSample(ntaken,s);
++ntaken;
if (ncurr>=startSample && ncurr<=endSample) {
digi.setSample(ntaken,s);
++ntaken;
}
ncurr++;
}
ncurr++;
digi.setSize(ntaken);
}
else if(flavor==7){ //similar to VME flavor 6, used for premix in MC
for (++i; i!=iend && !i.isHeader(); ++i) {
if (ncurr>=startSample && ncurr<=endSample) {
HcalQIESample sample(i.adc(),i.capid(),fiber,fiberchan,i.dataValid(),i.errFlags());
digi.setSample(ntaken,sample);
++ntaken;
}
ncurr++;
}
digi.setSize(ntaken);
}
digi.setSize(ntaken);
}

}


Expand Down Expand Up @@ -705,7 +720,7 @@ void HcalUnpacker::unpackUTCA(const FEDRawData& raw, const HcalElectronicsMap& e
#endif
}
}
else if (i.flavor()==0x5) { // Old-style digis
else if (i.flavor()==5 || (i.flavor()==7 && i.technicalDataType()==15)) { // Old-style digis
int ifiber=((i.channelid()>>2)&0x1F);
int ichan=(i.channelid()&0x3);
HcalElectronicsId eid(crate,slot,ifiber,ichan, false);
Expand Down

0 comments on commit 0bf96d3

Please sign in to comment.