Skip to content

Commit

Permalink
Merge pull request #28330 from lwang046/Hcal-TDC-CMSSW_11_0_X
Browse files Browse the repository at this point in the history
HCAL: implementation of TDC simulation functionality for Phase1 HB/HE
  • Loading branch information
cmsbuild committed Nov 6, 2019
2 parents 74e3c77 + 455061f commit 0338c9d
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 117 deletions.
7 changes: 7 additions & 0 deletions DataFormats/HcalDigi/interface/QIE11DataFrame.h
Expand Up @@ -99,6 +99,13 @@ class QIE11DataFrame {
}
/// get the sample
constexpr inline Sample operator[](edm::DataFrame::size_type i) const { return Sample(m_data, i + HEADER_WORDS); }

// set flavor
constexpr void setFlavor(int flavor) {
m_data[0] &= 0x9FFF; // inversion of flavor mask
m_data[0] |= ((flavor & MASK_FLAVOR) << OFFSET_FLAVOR);
}

constexpr void setCapid0(int cap0) {
if (flavor() == FLAVOR_HB) {
for (int i = 0; i < samples(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/HcalDigi/src/QIE11DataFrame.cc
Expand Up @@ -3,7 +3,7 @@

std::ostream& operator<<(std::ostream& s, const QIE11DataFrame& digi) {
if (digi.detid().det() == DetId::Hcal) {
s << HcalGenericDetId(digi.detid());
s << "DetID=" << HcalGenericDetId(digi.detid()) << " flavor=" << digi.flavor();
} else {
s << "DetId(" << digi.detid().rawId() << ")";
}
Expand Down
6 changes: 5 additions & 1 deletion EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc
Expand Up @@ -118,7 +118,7 @@ void HcalDigiToRawuHTR::produce(edm::StreamID id, edm::Event& iEvent, const edm:
int presamples = qiedf.presamples();

/* Defining a custom index that will encode only
the information about the crate and slot of a
the information about the crate and slot of a
given channel: crate: bits 0-7
slot: bits 8-12 */

Expand All @@ -144,6 +144,10 @@ void HcalDigiToRawuHTR::produce(edm::StreamID id, edm::Event& iEvent, const edm:
int uhtrIndex = ((slotId & 0xF) << 8) | (crateId & 0xFF);
int presamples = qiedf.presamples();

// convert to hb qie data if hb
if (HcalDetId(detid.rawId()).subdet() == HcalSubdetector::HcalBarrel)
qiedf = convertHB(qiedf);

if (!uhtrs.exist(uhtrIndex)) {
uhtrs.newUHTR(uhtrIndex, presamples);
}
Expand Down
91 changes: 79 additions & 12 deletions EventFilter/HcalRawToDigi/plugins/PackerHelp.h
Expand Up @@ -114,7 +114,9 @@ namespace QIE10HeaderSpec {
static const int MASK_HEADER_BIT = 0x1;
} // namespace QIE10HeaderSpec

namespace QIE11HeaderSpec {
// QIE11 specifications for various flavors

namespace QIE11HeaderSpec0 {
static const int OFFSET_FIBERCHAN = 0;
static const int MASK_FIBERCHAN = 0x7;
static const int OFFSET_FIBER = 3;
Expand All @@ -127,7 +129,22 @@ namespace QIE11HeaderSpec {
static const int MASK_FLAVOR = 0x7;
static const int OFFSET_HEADER_BIT = 15;
static const int MASK_HEADER_BIT = 0x1;
} // namespace QIE11HeaderSpec
} // namespace QIE11HeaderSpec0

namespace QIE11HeaderSpec3 {
static const int OFFSET_FIBERCHAN = 0;
static const int MASK_FIBERCHAN = 0x7;
static const int OFFSET_FIBER = 3;
static const int MASK_FIBER = 0x1F;
static const int OFFSET_MP = 8;
static const int MASK_MP = 0x1;
static const int OFFSET_LINKERROR = 11;
static const int MASK_LINKERROR = 0x1;
static const int OFFSET_FLAVOR = 12;
static const int MASK_FLAVOR = 0x7;
static const int OFFSET_HEADER_BIT = 15;
static const int MASK_HEADER_BIT = 0x1;
} // namespace QIE11HeaderSpec3

namespace TPHeaderSpec {
static const int OFFSET_TOWER = 0;
Expand Down Expand Up @@ -334,14 +351,14 @@ class UHTRpacker {

int fiber = eid.fiberIndex() + 1;
int fiberchan = eid.fiberChanId();
int fiberErr = qieSample.er();
int capid0 = qieSample.capid();

header |= (fiberchan & QIE8HeaderSpec::MASK_FIBERCHAN) << QIE8HeaderSpec::OFFSET_FIBERCHAN;
header |= ((fiber - 1) & QIE8HeaderSpec::MASK_FIBER) << QIE8HeaderSpec::OFFSET_FIBER;
if (flavor == 7) {
header |= (15 & QIE8HeaderSpec::MASK_TECHNICAL_DATA_TYPE) << QIE8HeaderSpec::OFFSET_TECHNICAL_DATA_TYPE;
} else {
int fiberErr = qieSample.er();
int capid0 = qieSample.capid();
header |= (capid0 & QIE8HeaderSpec::MASK_CAPID) << QIE8HeaderSpec::OFFSET_CAPID;
header |= (fiberErr & QIE8HeaderSpec::MASK_FIBERERR) << QIE8HeaderSpec::OFFSET_FIBERERR;
}
Expand Down Expand Up @@ -401,14 +418,24 @@ class UHTRpacker {

int fiber = eid.fiberIndex();
int fiberchan = eid.fiberChanId();
int capid0 = qiedf.samples() == 0 ? 0 : qiedf[0].capid(); // capacitor id for the first sample

header |= (fiberchan & QIE11HeaderSpec::MASK_FIBERCHAN) << QIE11HeaderSpec::OFFSET_FIBERCHAN;
header |= (fiber & QIE11HeaderSpec::MASK_FIBER) << QIE11HeaderSpec::OFFSET_FIBER;
header |= (capid0 & QIE11HeaderSpec::MASK_CAPID) << QIE11HeaderSpec::OFFSET_CAPID;
header |= (0x0 & QIE11HeaderSpec::MASK_FIBERERR) << QIE11HeaderSpec::OFFSET_FIBERERR;
header |= (0x0 & QIE11HeaderSpec::MASK_FLAVOR) << QIE11HeaderSpec::OFFSET_FLAVOR; //flavor
header |= (0x1 & QIE11HeaderSpec::MASK_HEADER_BIT) << QIE11HeaderSpec::OFFSET_HEADER_BIT;
int flavor = qiedf[0].flavor();

if (flavor == 3) {
header |= (fiberchan & QIE11HeaderSpec3::MASK_FIBERCHAN) << QIE11HeaderSpec3::OFFSET_FIBERCHAN;
header |= (fiber & QIE11HeaderSpec3::MASK_FIBER) << QIE11HeaderSpec3::OFFSET_FIBER;
header |= (0x0 & QIE11HeaderSpec3::MASK_MP) << QIE11HeaderSpec3::OFFSET_MP;
header |= (0x0 & QIE11HeaderSpec3::MASK_LINKERROR) << QIE11HeaderSpec3::OFFSET_LINKERROR;
header |= (flavor & QIE11HeaderSpec3::MASK_FLAVOR) << QIE11HeaderSpec3::OFFSET_FLAVOR; //flavor
header |= (0x1 & QIE11HeaderSpec3::MASK_HEADER_BIT) << QIE11HeaderSpec3::OFFSET_HEADER_BIT;
} else {
int capid0 = qiedf[0].capid();
header |= (fiberchan & QIE11HeaderSpec0::MASK_FIBERCHAN) << QIE11HeaderSpec0::OFFSET_FIBERCHAN;
header |= (fiber & QIE11HeaderSpec0::MASK_FIBER) << QIE11HeaderSpec0::OFFSET_FIBER;
header |= (capid0 & QIE11HeaderSpec0::MASK_CAPID) << QIE11HeaderSpec0::OFFSET_CAPID;
header |= (0x0 & QIE11HeaderSpec0::MASK_FIBERERR) << QIE11HeaderSpec0::OFFSET_FIBERERR;
header |= (flavor & QIE11HeaderSpec0::MASK_FLAVOR) << QIE11HeaderSpec0::OFFSET_FLAVOR; //flavor
header |= (0x1 & QIE11HeaderSpec0::MASK_HEADER_BIT) << QIE11HeaderSpec0::OFFSET_HEADER_BIT;
}

return header;
}
Expand Down Expand Up @@ -587,4 +614,44 @@ class UHTRpacker {
};
};

// converts HE QIE digies to HB data format

QIE11DataFrame convertHB(QIE11DataFrame qiehe) {
QIE11DataFrame qiehb = qiehe;
int adc, tdc;
bool soi;
int is = 0;

// flavor for HB digies is hardcoded here
static const int hbflavor = 3;

// iterator over samples
for (edm::DataFrame::const_iterator it = qiehe.begin(); it != qiehe.end(); ++it) {
if (it == qiehe.begin())
continue;
adc = qiehe[is].adc();
tdc = qiehe[is].tdc();
soi = qiehe[is].soi();

if (tdc >= 0 && tdc <= 24)
tdc = 0;
else if (tdc >= 25 && tdc <= 49)
tdc = 1;
else if (tdc == 63)
tdc = 2;
else if (tdc == 62)
tdc = 3;

qiehb.setSample(is, adc, tdc, soi);
is++;
};

// puting flavor is safe here because flavor is stored in the same bits for all flavors
qiehb.setFlavor(hbflavor);
int capid = qiehe[0].capid();
qiehb.setCapid0(capid);

return qiehb;
}

#endif
7 changes: 6 additions & 1 deletion SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h
Expand Up @@ -9,6 +9,7 @@
#include "SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h"
#include "SimCalorimetry/HcalSimAlgos/interface/HcalAmplifier.h"
#include "SimCalorimetry/HcalSimAlgos/interface/HcalCoderFactory.h"
#include "SimCalorimetry/HcalSimAlgos/interface/HcalSimParameterMap.h"

class HBHEDataFrame;
class HODataFrame;
Expand All @@ -23,7 +24,10 @@ namespace CLHEP {

class HcalElectronicsSim {
public:
HcalElectronicsSim(HcalAmplifier* amplifier, const HcalCoderFactory* coderFactory, bool PreMix);
HcalElectronicsSim(const HcalSimParameterMap* parameterMap,
HcalAmplifier* amplifier,
const HcalCoderFactory* coderFactory,
bool PreMix);
~HcalElectronicsSim();

void setDbService(const HcalDbService* service);
Expand Down Expand Up @@ -73,6 +77,7 @@ class HcalElectronicsSim {
template <class Digi>
void premix(CaloSamples& frame, Digi& result, double preMixFactor, unsigned preMixBits);

const HcalSimParameterMap* theParameterMap;
HcalAmplifier* theAmplifier;
const HcalCoderFactory* theCoderFactory;
HcalTDC theTDC;
Expand Down
2 changes: 2 additions & 0 deletions SimCalorimetry/HcalSimAlgos/interface/HcalSimParameters.h
Expand Up @@ -41,6 +41,7 @@ class HcalSimParameters : public CaloSimParameters {
int pixels(const DetId& detId) const;
bool doSiPMSmearing() const { return theSiPMSmearing; }

double threshold_currentTDC() const { return threshold_currentTDC_; }
double sipmTau() const { return theSiPMTau; }
double sipmDarkCurrentuA(const DetId& detId) const;
double sipmCrossTalk(const DetId& detId) const;
Expand All @@ -59,6 +60,7 @@ class HcalSimParameters : public CaloSimParameters {
bool doTimeSmear_;
HcalTimeSmearSettings theSmearSettings;
double theSiPMTau;
double threshold_currentTDC_;
};

#endif
14 changes: 7 additions & 7 deletions SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h
Expand Up @@ -5,6 +5,8 @@
#include "CalibFormats/CaloObjects/interface/CaloSamples.h"
#include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
#include "SimCalorimetry/HcalSimAlgos/interface/HcalTDCParameters.h"
#include "DataFormats/HcalDigi/interface/QIE11DataFrame.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"

class HcalDbService;

Expand All @@ -14,28 +16,26 @@ namespace CLHEP {

class HcalTDC {
public:
HcalTDC(unsigned int thresholdDAC = 12);
HcalTDC(double threshold_currentTDC = 0.);
~HcalTDC();

/// adds timing information to the digi
template <class Digi>
void timing(const CaloSamples& lf, Digi& digi, CLHEP::HepRandomEngine*) const;
/// template <class Digi>
void timing(const CaloSamples& lf, QIE11DataFrame& digi) const;

/// the Producer will probably update this every event
void setDbService(const HcalDbService* service);

void setThresholdDAC(unsigned int DAC) { theDAC = DAC; }
unsigned int getThresholdDAC() { return theDAC; }
double getThreshold() const { return threshold_currentTDC_; };

private:
double getThreshold(const HcalGenericDetId& detId, CLHEP::HepRandomEngine*) const;
double getHysteresisThreshold(double nominal) const;

HcalTDCParameters theTDCParameters;
const HcalDbService* theDbService;

unsigned int theDAC;

double threshold_currentTDC_;
double const lsb;
};

Expand Down
15 changes: 13 additions & 2 deletions SimCalorimetry/HcalSimAlgos/src/HcalElectronicsSim.cc
@@ -1,4 +1,6 @@
#include "SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h"
#include "SimCalorimetry/HcalSimAlgos/interface/HcalSimParameters.h"
#include "SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h"
#include "DataFormats/HcalDigi/interface/HBHEDataFrame.h"
#include "DataFormats/HcalDigi/interface/HODataFrame.h"
#include "DataFormats/HcalDigi/interface/HFDataFrame.h"
Expand All @@ -8,8 +10,12 @@
#include "CLHEP/Random/RandFlat.h"
#include <cmath>

HcalElectronicsSim::HcalElectronicsSim(HcalAmplifier* amplifier, const HcalCoderFactory* coderFactory, bool PreMixing)
: theAmplifier(amplifier),
HcalElectronicsSim::HcalElectronicsSim(const HcalSimParameterMap* parameterMap,
HcalAmplifier* amplifier,
const HcalCoderFactory* coderFactory,
bool PreMixing)
: theParameterMap(parameterMap),
theAmplifier(amplifier),
theCoderFactory(coderFactory),
theStartingCapId(0),
theStartingCapIdIsRandom(true),
Expand Down Expand Up @@ -137,6 +143,11 @@ void HcalElectronicsSim::analogToDigital(
void HcalElectronicsSim::analogToDigital(
CLHEP::HepRandomEngine* engine, CaloSamples& lf, QIE11DataFrame& result, double preMixFactor, unsigned preMixBits) {
analogToDigitalImpl(engine, lf, result, preMixFactor, preMixBits);
if (!PreMixDigis) {
const HcalSimParameters& pars = static_cast<const HcalSimParameters&>(theParameterMap->simParameters(lf.id()));
HcalTDC theTDC((pars.threshold_currentTDC()));
theTDC.timing(lf, result);
}
}

void HcalElectronicsSim::newEvent(CLHEP::HepRandomEngine* engine) {
Expand Down
3 changes: 2 additions & 1 deletion SimCalorimetry/HcalSimAlgos/src/HcalSimParameters.cc
Expand Up @@ -46,7 +46,8 @@ HcalSimParameters::HcalSimParameters(const edm::ParameterSet& p)
theSamplingFactors(p.getParameter<std::vector<double> >("samplingFactors")),
theSiPMSmearing(p.getParameter<bool>("doSiPMSmearing")),
doTimeSmear_(p.getParameter<bool>("timeSmearing")),
theSiPMTau(p.getParameter<double>("sipmTau")) {
theSiPMTau(p.getParameter<double>("sipmTau")),
threshold_currentTDC_(p.getParameter<double>("threshold_currentTDC")) {
defaultTimeSmearing();

edm::LogInfo("HcalSimParameters:") << " doSiPMsmearing = " << theSiPMSmearing;
Expand Down

0 comments on commit 0338c9d

Please sign in to comment.