From 21657f1e1d4d94526826ad4b00cbe5dd8191560f Mon Sep 17 00:00:00 2001 From: Long Date: Thu, 31 Oct 2019 19:02:52 +0100 Subject: [PATCH 1/8] Hcal TDC in Simulation --- .../HcalDigi/interface/QIE11DataFrame.h | 8 + DataFormats/HcalDigi/src/QIE11DataFrame.cc | 4 +- .../plugins/HcalDigiToRawuHTR.cc | 5 +- .../HcalRawToDigi/plugins/PackerHelp.h | 89 +++++++++- .../interface/HcalElectronicsSim.h | 4 +- .../interface/HcalSimParameters.h | 2 + .../HcalSimAlgos/interface/HcalTDC.h | 20 +-- .../HcalSimAlgos/src/HcalElectronicsSim.cc | 12 +- .../HcalSimAlgos/src/HcalSimParameters.cc | 3 +- SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc | 156 ++++++++---------- .../HcalSimAlgos/test/HcalDigitizerTest.cc | 2 +- .../python/hcalSimParameters_cfi.py | 6 + .../HcalSimProducers/src/HcalDigitizer.cc | 14 +- 13 files changed, 201 insertions(+), 124 deletions(-) diff --git a/DataFormats/HcalDigi/interface/QIE11DataFrame.h b/DataFormats/HcalDigi/interface/QIE11DataFrame.h index 84ae171f38b21..557adf5a6f8de 100644 --- a/DataFormats/HcalDigi/interface/QIE11DataFrame.h +++ b/DataFormats/HcalDigi/interface/QIE11DataFrame.h @@ -65,6 +65,7 @@ class QIE11DataFrame { /// Get the detector id constexpr DetId detid() const { return DetId(m_data.id()); } + constexpr HcalDetId hcaldetid() const { return HcalDetId(m_data.id()); } constexpr edm::DataFrame::id_type id() const { return m_data.id(); } /// more accessors constexpr edm::DataFrame::size_type size() const { return m_data.size(); } @@ -99,6 +100,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++) { diff --git a/DataFormats/HcalDigi/src/QIE11DataFrame.cc b/DataFormats/HcalDigi/src/QIE11DataFrame.cc index 09b5ba7a49237..2f2b7613cd95f 100644 --- a/DataFormats/HcalDigi/src/QIE11DataFrame.cc +++ b/DataFormats/HcalDigi/src/QIE11DataFrame.cc @@ -3,8 +3,8 @@ std::ostream& operator<<(std::ostream& s, const QIE11DataFrame& digi) { if (digi.detid().det() == DetId::Hcal) { - s << HcalGenericDetId(digi.detid()); - } else { + s << "DetID=" << HcalGenericDetId(digi.detid()) << " flavor=" << digi.flavor(); + } else { s << "DetId(" << digi.detid().rawId() << ")"; } s << " " << digi.samples() << " samples"; diff --git a/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc b/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc index defe0a922fea2..3ec6a39d0ba5d 100644 --- a/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc +++ b/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc @@ -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 */ @@ -144,6 +144,9 @@ 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 = convertHB2HE(qiedf); + if (!uhtrs.exist(uhtrIndex)) { uhtrs.newUHTR(uhtrIndex, presamples); } diff --git a/EventFilter/HcalRawToDigi/plugins/PackerHelp.h b/EventFilter/HcalRawToDigi/plugins/PackerHelp.h index 923085f0769d4..3bbc0076a55f6 100644 --- a/EventFilter/HcalRawToDigi/plugins/PackerHelp.h +++ b/EventFilter/HcalRawToDigi/plugins/PackerHelp.h @@ -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; @@ -129,6 +131,21 @@ namespace QIE11HeaderSpec { static const int MASK_HEADER_BIT = 0x1; } // namespace QIE11HeaderSpec +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 TPHeaderSpec { static const int OFFSET_TOWER = 0; static const int MASK_TOWER = 0xF; @@ -401,14 +418,33 @@ 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; + // capacitor id for the first sample + + // Flavor is added + + int flavor = qiedf[0].flavor(); + int capid0; + if (qiedf.samples() == 0) capid0=0; + if (flavor == 3) capid0 = qiedf[1].capid(); else capid0 = qiedf[0].capid(); + + // adding only cases for flavor 3 + + switch (flavor) { + case 0: + 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; + case 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; + }; return header; } @@ -587,4 +623,39 @@ class UHTRpacker { }; }; +// converts HE QIE digies to HB data format + + QIE11DataFrame convertHB2HE(QIE11DataFrame qiehe) { + QIE11DataFrame qiehb = qiehe; + int adc_, tdc_, capid_; + 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); + capid_ = qiehe[0].capid(); + qiehb.setCapid0(capid_); + + return qiehb; + } + #endif diff --git a/SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h b/SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h index 6136c39d7b239..6631f890b4e7f 100644 --- a/SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h +++ b/SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h @@ -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; @@ -23,7 +24,7 @@ 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); @@ -73,6 +74,7 @@ class HcalElectronicsSim { template void premix(CaloSamples& frame, Digi& result, double preMixFactor, unsigned preMixBits); + const HcalSimParameterMap* theParameterMap; HcalAmplifier* theAmplifier; const HcalCoderFactory* theCoderFactory; HcalTDC theTDC; diff --git a/SimCalorimetry/HcalSimAlgos/interface/HcalSimParameters.h b/SimCalorimetry/HcalSimAlgos/interface/HcalSimParameters.h index 5f369efcc7b61..42457ea1424ac 100644 --- a/SimCalorimetry/HcalSimAlgos/interface/HcalSimParameters.h +++ b/SimCalorimetry/HcalSimAlgos/interface/HcalSimParameters.h @@ -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; @@ -59,6 +60,7 @@ class HcalSimParameters : public CaloSimParameters { bool doTimeSmear_; HcalTimeSmearSettings theSmearSettings; double theSiPMTau; + double threshold_currentTDC_; }; #endif diff --git a/SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h b/SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h index 1fc0ad400d4bb..1236b76c73ef2 100644 --- a/SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h +++ b/SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h @@ -1,10 +1,11 @@ -// -*- mode: c++ -*- +// -*- mode: c++ -*- #ifndef HcalSimAlgos_HcalTDC_h #define HcalSimAlgos_HcalTDC_h #include "CalibFormats/CaloObjects/interface/CaloSamples.h" #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h" #include "SimCalorimetry/HcalSimAlgos/interface/HcalTDCParameters.h" +#include "DataFormats/HcalDigi/interface/QIE11DataFrame.h" class HcalDbService; @@ -13,29 +14,28 @@ namespace CLHEP { } class HcalTDC { + public: - HcalTDC(unsigned int thresholdDAC = 12); + HcalTDC(double threshold_currentTDC = 0.); ~HcalTDC(); /// adds timing information to the digi - template - void timing(const CaloSamples& lf, Digi& digi, CLHEP::HepRandomEngine*) const; + /// template + void timing(const CaloSamples & lf, QIE11DataFrame & digi) const; /// the Producer will probably update this every event - void setDbService(const HcalDbService* service); + 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; + const HcalDbService * theDbService; unsigned int theDAC; - + double threshold_currentTDC_; double const lsb; }; diff --git a/SimCalorimetry/HcalSimAlgos/src/HcalElectronicsSim.cc b/SimCalorimetry/HcalSimAlgos/src/HcalElectronicsSim.cc index 5458d920ac317..3e8cfe727a237 100644 --- a/SimCalorimetry/HcalSimAlgos/src/HcalElectronicsSim.cc +++ b/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" @@ -8,8 +10,9 @@ #include "CLHEP/Random/RandFlat.h" #include -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), @@ -137,6 +140,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(theParameterMap->simParameters(lf.id())); + HcalTDC theTDC((pars.threshold_currentTDC())); + theTDC.timing(lf, result); + } } void HcalElectronicsSim::newEvent(CLHEP::HepRandomEngine* engine) { diff --git a/SimCalorimetry/HcalSimAlgos/src/HcalSimParameters.cc b/SimCalorimetry/HcalSimAlgos/src/HcalSimParameters.cc index 3b739fd7e146c..c731e663483db 100644 --- a/SimCalorimetry/HcalSimAlgos/src/HcalSimParameters.cc +++ b/SimCalorimetry/HcalSimAlgos/src/HcalSimParameters.cc @@ -46,7 +46,8 @@ HcalSimParameters::HcalSimParameters(const edm::ParameterSet& p) theSamplingFactors(p.getParameter >("samplingFactors")), theSiPMSmearing(p.getParameter("doSiPMSmearing")), doTimeSmear_(p.getParameter("timeSmearing")), - theSiPMTau(p.getParameter("sipmTau")) { + theSiPMTau(p.getParameter("sipmTau")), + threshold_currentTDC_(p.getParameter("threshold_currentTDC")) { defaultTimeSmearing(); edm::LogInfo("HcalSimParameters:") << " doSiPMsmearing = " << theSiPMSmearing; diff --git a/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc b/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc index 935dfef245c33..94a2e321c2058 100644 --- a/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc +++ b/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc @@ -5,31 +5,26 @@ #include "CLHEP/Random/RandGaussQ.h" -HcalTDC::HcalTDC(unsigned int thresholdDAC) - : theTDCParameters(), theDbService(nullptr), theDAC(thresholdDAC), lsb(3.74) {} -HcalTDC::~HcalTDC() {} +HcalTDC::HcalTDC(double threshold_currentTDC) : theTDCParameters(), + theDbService(nullptr), + threshold_currentTDC_(threshold_currentTDC), + lsb(3.74) {} -template -void HcalTDC::timing(const CaloSamples& lf, Digi& digi, CLHEP::HepRandomEngine* engine) const { - float const TDC_Threshold(getThreshold(digi.id(), engine)); - float const TDC_Threshold_hyst(TDC_Threshold); - bool risingReady(true), fallingReady(false); +HcalTDC::~HcalTDC() { +} + +//template +void HcalTDC::timing(const CaloSamples& lf, QIE11DataFrame & digi) const { + + float const TDC_Threshold(getThreshold()); + bool risingReady(true); int tdcBins = theTDCParameters.nbins(); - // start with a loop over 10 samples - bool hasTDCValues = true; - if (lf.preciseSize() == 0) - hasTDCValues = false; - - // "AC" hysteresis from Tom: There cannot be a second transition - // within the QIE within 3ns - int const rising_ac_hysteresis(5); - int lastRisingEdge(0); - - // if (hasTDCValues) - // std::cout << digi.id() - // << " threshold: " << TDC_Threshold - // << '\n'; + bool hasTDCValues=true; + if (lf.preciseSize()==0 ) hasTDCValues=false; + + //std::cout << "TDC threshold: " << TDC_Threshold << std::endl; + for (int ibin = 0; ibin < lf.size(); ++ibin) { /* If in a given 25ns bunch/time sample, the pulse is above @@ -45,83 +40,62 @@ void HcalTDC::timing(const CaloSamples& lf, Digi& digi, CLHEP::HepRandomEngine* TDC_FallingEdge=62. */ // special codes - int TDC_RisingEdge = (risingReady) ? theTDCParameters.noTransitionCode() : theTDCParameters.alreadyTransitionCode(); - int TDC_FallingEdge = - (fallingReady) ? theTDCParameters.alreadyTransitionCode() : theTDCParameters.noTransitionCode(); + int TDC_RisingEdge = (risingReady) ? + theTDCParameters.noTransitionCode() : + theTDCParameters.alreadyTransitionCode(); int preciseBegin = ibin * tdcBins; int preciseEnd = preciseBegin + tdcBins; - if (hasTDCValues) { - // std::cout << " alreadyOn: " << alreadyOn << '\n'; - for (int i = preciseBegin; i < preciseEnd; ++i) { - // std::cout << " preciseBin: " << i - // << " preciseAt(i): " << lf.preciseAt(i); - if ((fallingReady) && (i % 3 == 0) && (lf.preciseAt(i) < TDC_Threshold)) { - fallingReady = false; - TDC_FallingEdge = i - preciseBegin; - // std::cout << " falling "; - } - if ((risingReady) && (lf.preciseAt(i) > TDC_Threshold)) { - risingReady = false; - TDC_RisingEdge = i - preciseBegin; - lastRisingEdge = 0; - // std::cout << " rising "; - } - // std::cout << '\n'; - //This is the place for hysteresis code. Need to to arm the - //tdc by setting the risingReady or fallingReady to true. + if ( hasTDCValues) { + for(int i = preciseBegin; i < preciseEnd; ++i) { //find the TDC time value in each TS - if ((!fallingReady) && (lf.preciseAt(i) > TDC_Threshold)) { - fallingReady = true; - if (TDC_FallingEdge == theTDCParameters.alreadyTransitionCode()) - TDC_FallingEdge = theTDCParameters.noTransitionCode(); - } - if ((!risingReady) && (lastRisingEdge > rising_ac_hysteresis) && (lf.preciseAt(i) < TDC_Threshold_hyst)) { - risingReady = true; - if (TDC_RisingEdge == theTDCParameters.alreadyTransitionCode()) - TDC_RisingEdge = theTDCParameters.noTransitionCode(); - } - ++lastRisingEdge; - } - } - // change packing to allow for special codes - int packedTDC = TDC_RisingEdge + (tdcBins * 2) * TDC_FallingEdge; - digi.setSample(ibin, digi.adc(ibin), packedTDC, true); - // if ( hasTDCValues) { - // std::cout << " sample: " << ibin - // << " adc: " << digi.adc(ibin) - // << " fC: " << digi[ibin].nominal_fC() - // << " risingEdge: " << TDC_RisingEdge - // << " fallingEdge: " << TDC_FallingEdge - // << " packedTDC: " << packedTDC - // << std::endl; - // } - } // loop over bunch crossing bins -} + //std::cout << " preciseBin: " << i << " preciseAt(i): " << lf.preciseAt(i) << std::endl; -double HcalTDC::getThreshold(const HcalGenericDetId& detId, CLHEP::HepRandomEngine* engine) const { - // subtract off pedestal and noise once - double pedestal = theDbService->getHcalCalibrations(detId).pedestal(0); - double pedestalWidth = theDbService->getHcalCalibrationWidths(detId).pedestal(0); - // here the TDCthreshold_ is a multiple of the least significant bit - // for the TDC portion of the QIE. The nominal reference is 40 uA which is - // divided by an 8 bit DAC. This means the least significant bit is 0.135 uA - // in the TDC circuit or 3.74 uA at the input current. + if( (!risingReady) && (i==preciseBegin) && (i!=0) ) { + if( ((lf.preciseAt(i+1) - lf.preciseAt(i-1)) > TDC_Threshold) ){ + TDC_RisingEdge = theTDCParameters.alreadyTransitionCode(); + break; + } else risingReady = true; + } - // the pedestal is assumed to be evenly distributed in time with some - // random variation. + if(risingReady){ + if( i!=399 && i!=0 && (lf.preciseAt(i+1) - lf.preciseAt(i-1)) > TDC_Threshold){ + risingReady = false; + TDC_RisingEdge = i-preciseBegin; + } else if(i==0 && (lf.preciseAt(i+1) - lf.preciseAt(i))/0.5 > TDC_Threshold){ + risingReady = false; + TDC_RisingEdge = i-preciseBegin; + } else if(i==(preciseEnd-1)) TDC_RisingEdge = theTDCParameters.noTransitionCode(); + } - return lsb * theDAC - CLHEP::RandGaussQ::shoot(engine, pedestal, pedestalWidth) / theTDCParameters.deltaT() / - theTDCParameters.nbins(); -} + if( (!risingReady) && (i==(preciseEnd-1)) && (i!=399) ){ + if( ((lf.preciseAt(i+1) - lf.preciseAt(i-1)) < TDC_Threshold) ) { + risingReady = true; + } + } + } //end of looping precise bins + } -double HcalTDC::getHysteresisThreshold(double nominal) const { - // the TDC will "re-arm" when it crosses the threshold minus 2.5 mV. - // the lsb is 44kOhm * (3.74 uA / 24) = 6.86 mV. 2.5 mV is 0.36 lsb. - // with the this means that the hysteresis it isn't far from the nominal - // threshold + // change packing to allow for special codes + int packedTDC = TDC_RisingEdge; + digi.setSample(ibin, digi[ibin].adc(), packedTDC, digi[ibin].soi()); - return nominal - 0.365 * lsb; + /*if ( hasTDCValues) { + if(digi.hcaldetid().ieta()==1&&digi.hcaldetid().iphi()==1){ + std::cout << " Depth: " << digi.hcaldetid().depth() + << " sample: " << ibin << " adc: " << digi[ibin].adc() + << " capid: " << digi[ibin].capid() + << " risingEdge: " << TDC_RisingEdge + << " packedTDC: " << packedTDC + << " tdc: " << digi[ibin].tdc() + << " flavor(HE=0/HB=3): " << digi.flavor() + << " SubDet(HE=2/HB=1): " << digi.hcaldetid().subdet() + << std::endl; + } + }*/ + } // loop over bunch crossing bins } -void HcalTDC::setDbService(const HcalDbService* service) { theDbService = service; } +void HcalTDC::setDbService(const HcalDbService * service) { + theDbService = service; +} diff --git a/SimCalorimetry/HcalSimAlgos/test/HcalDigitizerTest.cc b/SimCalorimetry/HcalSimAlgos/test/HcalDigitizerTest.cc index ab1919942b7d0..d8259419a7652 100644 --- a/SimCalorimetry/HcalSimAlgos/test/HcalDigitizerTest.cc +++ b/SimCalorimetry/HcalSimAlgos/test/HcalDigitizerTest.cc @@ -230,7 +230,7 @@ void HcalDigitizerTest::analyze(const edm::Event& iEvent, const edm::EventSetup& bool PM2 = false; HcalAmplifier amplifier(¶meterMap, addNoise, PM1, PM2); HcalCoderFactory coderFactory(HcalCoderFactory::NOMINAL); - HcalElectronicsSim electronicsSim(&lifier, &coderFactory, PM1); + HcalElectronicsSim electronicsSim(¶meterMap, &lifier, &coderFactory, PM1); amplifier.setDbService(&calibratorHandle); amplifier.setTimeSlew(hcalTimeSlew_delay_); parameterMap.setDbService(&calibratorHandle); diff --git a/SimCalorimetry/HcalSimProducers/python/hcalSimParameters_cfi.py b/SimCalorimetry/HcalSimProducers/python/hcalSimParameters_cfi.py index 8dff034d149f4..b4d937acca452 100644 --- a/SimCalorimetry/HcalSimProducers/python/hcalSimParameters_cfi.py +++ b/SimCalorimetry/HcalSimProducers/python/hcalSimParameters_cfi.py @@ -21,6 +21,7 @@ timePhase = cms.double(14.0), doSiPMSmearing = cms.bool(False), sipmTau = cms.double(0.), + threshold_currentTDC = cms.double(18.7), ), hf2 = cms.PSet( readoutFrameSize = cms.int32(4), @@ -33,6 +34,7 @@ timePhase = cms.double(13.0), doSiPMSmearing = cms.bool(False), sipmTau = cms.double(0.), + threshold_currentTDC = cms.double(18.7), ), ho = cms.PSet( readoutFrameSize = cms.int32(10), @@ -50,6 +52,7 @@ siPMCode = cms.int32(2), doSiPMSmearing = cms.bool(False), sipmTau = cms.double(5.), + threshold_currentTDC = cms.double(18.7), ), hb = cms.PSet( readoutFrameSize = cms.int32(10), @@ -67,6 +70,7 @@ timeSmearing = cms.bool(True), doSiPMSmearing = cms.bool(False), sipmTau = cms.double(0.), + threshold_currentTDC = cms.double(18.7), ), he = cms.PSet( readoutFrameSize = cms.int32(10), @@ -83,6 +87,7 @@ timeSmearing = cms.bool(True), doSiPMSmearing = cms.bool(False), sipmTau = cms.double(0.), + threshold_currentTDC = cms.double(18.7), ), zdc = cms.PSet( readoutFrameSize = cms.int32(10), @@ -95,6 +100,7 @@ timePhase = cms.double(-4.0), doSiPMSmearing = cms.bool(False), sipmTau = cms.double(0.), + threshold_currentTDC = cms.double(18.7), ), ) diff --git a/SimCalorimetry/HcalSimProducers/src/HcalDigitizer.cc b/SimCalorimetry/HcalSimProducers/src/HcalDigitizer.cc index 1fe45aba5819d..a0e24de8bb28b 100644 --- a/SimCalorimetry/HcalSimProducers/src/HcalDigitizer.cc +++ b/SimCalorimetry/HcalSimProducers/src/HcalDigitizer.cc @@ -129,16 +129,18 @@ HcalDigitizer::HcalDigitizer(const edm::ParameterSet &ps, edm::ConsumesCollector theCoderFactory = std::make_unique(HcalCoderFactory::DB); - theHBHEElectronicsSim = std::make_unique(theHBHEAmplifier.get(), theCoderFactory.get(), PreMix1); - theHFElectronicsSim = std::make_unique(theHFAmplifier.get(), theCoderFactory.get(), PreMix1); - theHOElectronicsSim = std::make_unique(theHOAmplifier.get(), theCoderFactory.get(), PreMix1); - theZDCElectronicsSim = std::make_unique(theZDCAmplifier.get(), theCoderFactory.get(), PreMix1); + theHBHEElectronicsSim = std::make_unique(&theParameterMap, theHBHEAmplifier.get(), theCoderFactory.get(), PreMix1); + theHFElectronicsSim = std::make_unique(&theParameterMap, theHFAmplifier.get(), theCoderFactory.get(), PreMix1); + theHOElectronicsSim = std::make_unique(&theParameterMap, theHOAmplifier.get(), theCoderFactory.get(), PreMix1); + theZDCElectronicsSim = std::make_unique(&theParameterMap, theZDCAmplifier.get(), theCoderFactory.get(), PreMix1); theHFQIE10ElectronicsSim = - std::make_unique(theHFQIE10Amplifier.get(), + std::make_unique(&theParameterMap, + theHFQIE10Amplifier.get(), theCoderFactory.get(), PreMix1); // should this use a different coder factory? theHBHEQIE11ElectronicsSim = - std::make_unique(theHBHEQIE11Amplifier.get(), + std::make_unique(&theParameterMap, + theHBHEQIE11Amplifier.get(), theCoderFactory.get(), PreMix1); // should this use a different coder factory? From fe385f7f9a9aa57366332fcf8f4bcdaf32d748d8 Mon Sep 17 00:00:00 2001 From: Long Date: Thu, 31 Oct 2019 23:13:35 +0100 Subject: [PATCH 2/8] Delete obselete HcalDetId in QIE11DataFrame.h --- DataFormats/HcalDigi/interface/QIE11DataFrame.h | 1 - SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h | 1 + SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc | 3 +-- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/DataFormats/HcalDigi/interface/QIE11DataFrame.h b/DataFormats/HcalDigi/interface/QIE11DataFrame.h index 557adf5a6f8de..c9fd386210b36 100644 --- a/DataFormats/HcalDigi/interface/QIE11DataFrame.h +++ b/DataFormats/HcalDigi/interface/QIE11DataFrame.h @@ -65,7 +65,6 @@ class QIE11DataFrame { /// Get the detector id constexpr DetId detid() const { return DetId(m_data.id()); } - constexpr HcalDetId hcaldetid() const { return HcalDetId(m_data.id()); } constexpr edm::DataFrame::id_type id() const { return m_data.id(); } /// more accessors constexpr edm::DataFrame::size_type size() const { return m_data.size(); } diff --git a/SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h b/SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h index 1236b76c73ef2..fb552fb07d24c 100644 --- a/SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h +++ b/SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h @@ -6,6 +6,7 @@ #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; diff --git a/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc b/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc index 94a2e321c2058..dd6e6ae778d4b 100644 --- a/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc +++ b/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc @@ -2,7 +2,6 @@ #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h" #include "CalibFormats/HcalObjects/interface/HcalDbService.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" - #include "CLHEP/Random/RandGaussQ.h" @@ -81,7 +80,7 @@ void HcalTDC::timing(const CaloSamples& lf, QIE11DataFrame & digi) const { digi.setSample(ibin, digi[ibin].adc(), packedTDC, digi[ibin].soi()); /*if ( hasTDCValues) { - if(digi.hcaldetid().ieta()==1&&digi.hcaldetid().iphi()==1){ + if(HcalDetId(hcaldetid()).ieta()==1&&HcalDetId(hcaldetid()).iphi()==1){ std::cout << " Depth: " << digi.hcaldetid().depth() << " sample: " << ibin << " adc: " << digi[ibin].adc() << " capid: " << digi[ibin].capid() From 4929691f013ef28f5b5813005f719b3e2e0dbb61 Mon Sep 17 00:00:00 2001 From: Long Date: Thu, 31 Oct 2019 23:40:13 +0100 Subject: [PATCH 3/8] adaptation to HcalElectronicsSim class contructor change --- SimCalorimetry/HcalTestBeam/interface/HcalTBDigiProducer.h | 2 ++ SimCalorimetry/HcalTestBeam/src/HcalTBDigiProducer.cc | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/SimCalorimetry/HcalTestBeam/interface/HcalTBDigiProducer.h b/SimCalorimetry/HcalTestBeam/interface/HcalTBDigiProducer.h index 58f8e40dd8632..f5ffa7d32b5ce 100644 --- a/SimCalorimetry/HcalTestBeam/interface/HcalTBDigiProducer.h +++ b/SimCalorimetry/HcalTestBeam/interface/HcalTBDigiProducer.h @@ -17,6 +17,7 @@ #include "SimCalorimetry/HcalTestBeam/interface/HcalTBSimParameterMap.h" #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h" #include "SimGeneral/MixingModule/interface/DigiAccumulatorMixMod.h" +#include "SimCalorimetry/HcalSimAlgos/interface/HcalSimParameters.h" #include #include @@ -62,6 +63,7 @@ class HcalTBDigiProducer : public DigiAccumulatorMixMod { typedef CaloTDigitizer HODigitizer; HcalTBSimParameterMap *theParameterMap; + HcalSimParameterMap *paraMap; CaloVShape *theHcalShape; CaloVShape *theHcalIntegratedShape; diff --git a/SimCalorimetry/HcalTestBeam/src/HcalTBDigiProducer.cc b/SimCalorimetry/HcalTestBeam/src/HcalTBDigiProducer.cc index 5297ed875e86c..108fd7ddf0876 100644 --- a/SimCalorimetry/HcalTestBeam/src/HcalTBDigiProducer.cc +++ b/SimCalorimetry/HcalTestBeam/src/HcalTBDigiProducer.cc @@ -23,6 +23,7 @@ HcalTBDigiProducer::HcalTBDigiProducer(const edm::ParameterSet &ps, edm::ProducerBase &mixMod, edm::ConsumesCollector &iC) : theParameterMap(new HcalTBSimParameterMap(ps)), + paraMap(new HcalSimParameterMap(ps)), theHcalShape(new HcalShape()), theHcalIntegratedShape(new CaloShapeIntegrator(theHcalShape)), theHBHEResponse(new CaloHitResponse(theParameterMap, theHcalIntegratedShape)), @@ -53,7 +54,7 @@ HcalTBDigiProducer::HcalTBDigiProducer(const edm::ParameterSet &ps, bool dummy2 = false; // extra arguments for premixing theAmplifier = new HcalAmplifier(theParameterMap, doNoise, dummy1, dummy2); theCoderFactory = new HcalCoderFactory(HcalCoderFactory::DB); - theElectronicsSim = new HcalElectronicsSim(theAmplifier, theCoderFactory, dummy1); + theElectronicsSim = new HcalElectronicsSim(paraMap, theAmplifier, theCoderFactory, dummy1); double minFCToDelay = ps.getParameter("minFCToDelay"); bool doTimeSlew = ps.getParameter("doTimeSlew"); From 4098fd2db31a4515233fe3a349ad1308daaa0fd2 Mon Sep 17 00:00:00 2001 From: Long Date: Fri, 1 Nov 2019 09:31:45 +0100 Subject: [PATCH 4/8] clang-format --- .../HcalDigi/interface/QIE11DataFrame.h | 4 +- DataFormats/HcalDigi/src/QIE11DataFrame.cc | 4 +- .../plugins/HcalDigiToRawuHTR.cc | 3 +- .../HcalRawToDigi/plugins/PackerHelp.h | 79 +++++++++++-------- .../interface/HcalElectronicsSim.h | 5 +- .../HcalSimAlgos/interface/HcalTDC.h | 9 +-- .../HcalSimAlgos/src/HcalElectronicsSim.cc | 7 +- SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc | 78 +++++++++--------- .../HcalSimProducers/src/HcalDigitizer.cc | 20 +++-- 9 files changed, 111 insertions(+), 98 deletions(-) diff --git a/DataFormats/HcalDigi/interface/QIE11DataFrame.h b/DataFormats/HcalDigi/interface/QIE11DataFrame.h index c9fd386210b36..d2433a54f8e32 100644 --- a/DataFormats/HcalDigi/interface/QIE11DataFrame.h +++ b/DataFormats/HcalDigi/interface/QIE11DataFrame.h @@ -102,8 +102,8 @@ class QIE11DataFrame { // set flavor constexpr void setFlavor(int flavor) { - m_data[0] &= 0x9FFF; // inversion of flavor mask - m_data[0] |= ((flavor&MASK_FLAVOR) << OFFSET_FLAVOR); + m_data[0] &= 0x9FFF; // inversion of flavor mask + m_data[0] |= ((flavor & MASK_FLAVOR) << OFFSET_FLAVOR); } constexpr void setCapid0(int cap0) { diff --git a/DataFormats/HcalDigi/src/QIE11DataFrame.cc b/DataFormats/HcalDigi/src/QIE11DataFrame.cc index 2f2b7613cd95f..9e8811ca9a475 100644 --- a/DataFormats/HcalDigi/src/QIE11DataFrame.cc +++ b/DataFormats/HcalDigi/src/QIE11DataFrame.cc @@ -3,8 +3,8 @@ std::ostream& operator<<(std::ostream& s, const QIE11DataFrame& digi) { if (digi.detid().det() == DetId::Hcal) { - s << "DetID=" << HcalGenericDetId(digi.detid()) << " flavor=" << digi.flavor(); - } else { + s << "DetID=" << HcalGenericDetId(digi.detid()) << " flavor=" << digi.flavor(); + } else { s << "DetId(" << digi.detid().rawId() << ")"; } s << " " << digi.samples() << " samples"; diff --git a/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc b/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc index 3ec6a39d0ba5d..aec36482c37c1 100644 --- a/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc +++ b/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc @@ -145,7 +145,8 @@ void HcalDigiToRawuHTR::produce(edm::StreamID id, edm::Event& iEvent, const edm: int presamples = qiedf.presamples(); // convert to hb qie data if hb - if (HcalDetId(detid.rawId()).subdet() == HcalSubdetector::HcalBarrel) qiedf = convertHB2HE(qiedf); + if (HcalDetId(detid.rawId()).subdet() == HcalSubdetector::HcalBarrel) + qiedf = convertHB2HE(qiedf); if (!uhtrs.exist(uhtrIndex)) { uhtrs.newUHTR(uhtrIndex, presamples); diff --git a/EventFilter/HcalRawToDigi/plugins/PackerHelp.h b/EventFilter/HcalRawToDigi/plugins/PackerHelp.h index 3bbc0076a55f6..f4b88d27d59ae 100644 --- a/EventFilter/HcalRawToDigi/plugins/PackerHelp.h +++ b/EventFilter/HcalRawToDigi/plugins/PackerHelp.h @@ -129,7 +129,7 @@ namespace QIE11HeaderSpec0 { 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; @@ -144,7 +144,7 @@ namespace QIE11HeaderSpec3 { 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; @@ -418,14 +418,18 @@ class UHTRpacker { int fiber = eid.fiberIndex(); int fiberchan = eid.fiberChanId(); - // capacitor id for the first sample + // capacitor id for the first sample // Flavor is added int flavor = qiedf[0].flavor(); int capid0; - if (qiedf.samples() == 0) capid0=0; - if (flavor == 3) capid0 = qiedf[1].capid(); else capid0 = qiedf[0].capid(); + if (qiedf.samples() == 0) + capid0 = 0; + if (flavor == 3) + capid0 = qiedf[1].capid(); + else + capid0 = qiedf[0].capid(); // adding only cases for flavor 3 @@ -625,37 +629,42 @@ class UHTRpacker { // converts HE QIE digies to HB data format - QIE11DataFrame convertHB2HE(QIE11DataFrame qiehe) { - QIE11DataFrame qiehb = qiehe; - int adc_, tdc_, capid_; - 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++; - }; +QIE11DataFrame convertHB2HE(QIE11DataFrame qiehe) { + QIE11DataFrame qiehb = qiehe; + int adc_, tdc_, capid_; + 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); - capid_ = qiehe[0].capid(); - qiehb.setCapid0(capid_); + // puting flavor is safe here because flavor is stored in the same bits for all flavors + qiehb.setFlavor(hbflavor); + capid_ = qiehe[0].capid(); + qiehb.setCapid0(capid_); - return qiehb; - } + return qiehb; +} #endif diff --git a/SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h b/SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h index 6631f890b4e7f..90a3548803911 100644 --- a/SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h +++ b/SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h @@ -24,7 +24,10 @@ namespace CLHEP { class HcalElectronicsSim { public: - HcalElectronicsSim(const HcalSimParameterMap* parameterMap, HcalAmplifier* amplifier, const HcalCoderFactory* coderFactory, bool PreMix); + HcalElectronicsSim(const HcalSimParameterMap* parameterMap, + HcalAmplifier* amplifier, + const HcalCoderFactory* coderFactory, + bool PreMix); ~HcalElectronicsSim(); void setDbService(const HcalDbService* service); diff --git a/SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h b/SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h index fb552fb07d24c..f337e030c920e 100644 --- a/SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h +++ b/SimCalorimetry/HcalSimAlgos/interface/HcalTDC.h @@ -1,4 +1,4 @@ -// -*- mode: c++ -*- +// -*- mode: c++ -*- #ifndef HcalSimAlgos_HcalTDC_h #define HcalSimAlgos_HcalTDC_h @@ -15,17 +15,16 @@ namespace CLHEP { } class HcalTDC { - public: HcalTDC(double threshold_currentTDC = 0.); ~HcalTDC(); /// adds timing information to the digi /// template - void timing(const CaloSamples & lf, QIE11DataFrame & digi) const; + void timing(const CaloSamples& lf, QIE11DataFrame& digi) const; /// the Producer will probably update this every event - void setDbService(const HcalDbService * service); + void setDbService(const HcalDbService* service); void setThresholdDAC(unsigned int DAC) { theDAC = DAC; } unsigned int getThresholdDAC() { return theDAC; } @@ -33,7 +32,7 @@ class HcalTDC { private: HcalTDCParameters theTDCParameters; - const HcalDbService * theDbService; + const HcalDbService* theDbService; unsigned int theDAC; double threshold_currentTDC_; diff --git a/SimCalorimetry/HcalSimAlgos/src/HcalElectronicsSim.cc b/SimCalorimetry/HcalSimAlgos/src/HcalElectronicsSim.cc index 3e8cfe727a237..5208fb4def48e 100644 --- a/SimCalorimetry/HcalSimAlgos/src/HcalElectronicsSim.cc +++ b/SimCalorimetry/HcalSimAlgos/src/HcalElectronicsSim.cc @@ -10,7 +10,10 @@ #include "CLHEP/Random/RandFlat.h" #include -HcalElectronicsSim::HcalElectronicsSim(const HcalSimParameterMap* parameterMap, HcalAmplifier* amplifier, const HcalCoderFactory* coderFactory, bool PreMixing) +HcalElectronicsSim::HcalElectronicsSim(const HcalSimParameterMap* parameterMap, + HcalAmplifier* amplifier, + const HcalCoderFactory* coderFactory, + bool PreMixing) : theParameterMap(parameterMap), theAmplifier(amplifier), theCoderFactory(coderFactory), @@ -140,7 +143,7 @@ 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) { + if (!PreMixDigis) { const HcalSimParameters& pars = static_cast(theParameterMap->simParameters(lf.id())); HcalTDC theTDC((pars.threshold_currentTDC())); theTDC.timing(lf, result); diff --git a/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc b/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc index dd6e6ae778d4b..e969f6d11f197 100644 --- a/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc +++ b/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc @@ -4,25 +4,21 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "CLHEP/Random/RandGaussQ.h" +HcalTDC::HcalTDC(double threshold_currentTDC) + : theTDCParameters(), theDbService(nullptr), threshold_currentTDC_(threshold_currentTDC), lsb(3.74) {} -HcalTDC::HcalTDC(double threshold_currentTDC) : theTDCParameters(), - theDbService(nullptr), - threshold_currentTDC_(threshold_currentTDC), - lsb(3.74) {} - -HcalTDC::~HcalTDC() { -} +HcalTDC::~HcalTDC() {} //template -void HcalTDC::timing(const CaloSamples& lf, QIE11DataFrame & digi) const { - +void HcalTDC::timing(const CaloSamples& lf, QIE11DataFrame& digi) const { float const TDC_Threshold(getThreshold()); bool risingReady(true); int tdcBins = theTDCParameters.nbins(); - bool hasTDCValues=true; - if (lf.preciseSize()==0 ) hasTDCValues=false; + bool hasTDCValues = true; + if (lf.preciseSize() == 0) + hasTDCValues = false; - //std::cout << "TDC threshold: " << TDC_Threshold << std::endl; + //std::cout << "TDC threshold: " << TDC_Threshold << std::endl; for (int ibin = 0; ibin < lf.size(); ++ibin) { /* @@ -39,40 +35,40 @@ void HcalTDC::timing(const CaloSamples& lf, QIE11DataFrame & digi) const { TDC_FallingEdge=62. */ // special codes - int TDC_RisingEdge = (risingReady) ? - theTDCParameters.noTransitionCode() : - theTDCParameters.alreadyTransitionCode(); + int TDC_RisingEdge = (risingReady) ? theTDCParameters.noTransitionCode() : theTDCParameters.alreadyTransitionCode(); int preciseBegin = ibin * tdcBins; int preciseEnd = preciseBegin + tdcBins; - if ( hasTDCValues) { - for(int i = preciseBegin; i < preciseEnd; ++i) { //find the TDC time value in each TS + if (hasTDCValues) { + for (int i = preciseBegin; i < preciseEnd; ++i) { //find the TDC time value in each TS - //std::cout << " preciseBin: " << i << " preciseAt(i): " << lf.preciseAt(i) << std::endl; + //std::cout << " preciseBin: " << i << " preciseAt(i): " << lf.preciseAt(i) << std::endl; - if( (!risingReady) && (i==preciseBegin) && (i!=0) ) { - if( ((lf.preciseAt(i+1) - lf.preciseAt(i-1)) > TDC_Threshold) ){ - TDC_RisingEdge = theTDCParameters.alreadyTransitionCode(); - break; - } else risingReady = true; - } + if ((!risingReady) && (i == preciseBegin) && (i != 0)) { + if (((lf.preciseAt(i + 1) - lf.preciseAt(i - 1)) > TDC_Threshold)) { + TDC_RisingEdge = theTDCParameters.alreadyTransitionCode(); + break; + } else + risingReady = true; + } - if(risingReady){ - if( i!=399 && i!=0 && (lf.preciseAt(i+1) - lf.preciseAt(i-1)) > TDC_Threshold){ - risingReady = false; - TDC_RisingEdge = i-preciseBegin; - } else if(i==0 && (lf.preciseAt(i+1) - lf.preciseAt(i))/0.5 > TDC_Threshold){ - risingReady = false; - TDC_RisingEdge = i-preciseBegin; - } else if(i==(preciseEnd-1)) TDC_RisingEdge = theTDCParameters.noTransitionCode(); - } + if (risingReady) { + if (i != 399 && i != 0 && (lf.preciseAt(i + 1) - lf.preciseAt(i - 1)) > TDC_Threshold) { + risingReady = false; + TDC_RisingEdge = i - preciseBegin; + } else if (i == 0 && (lf.preciseAt(i + 1) - lf.preciseAt(i)) / 0.5 > TDC_Threshold) { + risingReady = false; + TDC_RisingEdge = i - preciseBegin; + } else if (i == (preciseEnd - 1)) + TDC_RisingEdge = theTDCParameters.noTransitionCode(); + } - if( (!risingReady) && (i==(preciseEnd-1)) && (i!=399) ){ - if( ((lf.preciseAt(i+1) - lf.preciseAt(i-1)) < TDC_Threshold) ) { - risingReady = true; - } + if ((!risingReady) && (i == (preciseEnd - 1)) && (i != 399)) { + if (((lf.preciseAt(i + 1) - lf.preciseAt(i - 1)) < TDC_Threshold)) { + risingReady = true; } - } //end of looping precise bins + } + } //end of looping precise bins } // change packing to allow for special codes @@ -92,9 +88,7 @@ void HcalTDC::timing(const CaloSamples& lf, QIE11DataFrame & digi) const { << std::endl; } }*/ - } // loop over bunch crossing bins + } // loop over bunch crossing bins } -void HcalTDC::setDbService(const HcalDbService * service) { - theDbService = service; -} +void HcalTDC::setDbService(const HcalDbService* service) { theDbService = service; } diff --git a/SimCalorimetry/HcalSimProducers/src/HcalDigitizer.cc b/SimCalorimetry/HcalSimProducers/src/HcalDigitizer.cc index a0e24de8bb28b..bce520ca5c497 100644 --- a/SimCalorimetry/HcalSimProducers/src/HcalDigitizer.cc +++ b/SimCalorimetry/HcalSimProducers/src/HcalDigitizer.cc @@ -129,18 +129,22 @@ HcalDigitizer::HcalDigitizer(const edm::ParameterSet &ps, edm::ConsumesCollector theCoderFactory = std::make_unique(HcalCoderFactory::DB); - theHBHEElectronicsSim = std::make_unique(&theParameterMap, theHBHEAmplifier.get(), theCoderFactory.get(), PreMix1); - theHFElectronicsSim = std::make_unique(&theParameterMap, theHFAmplifier.get(), theCoderFactory.get(), PreMix1); - theHOElectronicsSim = std::make_unique(&theParameterMap, theHOAmplifier.get(), theCoderFactory.get(), PreMix1); - theZDCElectronicsSim = std::make_unique(&theParameterMap, theZDCAmplifier.get(), theCoderFactory.get(), PreMix1); + theHBHEElectronicsSim = + std::make_unique(&theParameterMap, theHBHEAmplifier.get(), theCoderFactory.get(), PreMix1); + theHFElectronicsSim = + std::make_unique(&theParameterMap, theHFAmplifier.get(), theCoderFactory.get(), PreMix1); + theHOElectronicsSim = + std::make_unique(&theParameterMap, theHOAmplifier.get(), theCoderFactory.get(), PreMix1); + theZDCElectronicsSim = + std::make_unique(&theParameterMap, theZDCAmplifier.get(), theCoderFactory.get(), PreMix1); theHFQIE10ElectronicsSim = - std::make_unique(&theParameterMap, - theHFQIE10Amplifier.get(), + std::make_unique(&theParameterMap, + theHFQIE10Amplifier.get(), theCoderFactory.get(), PreMix1); // should this use a different coder factory? theHBHEQIE11ElectronicsSim = - std::make_unique(&theParameterMap, - theHBHEQIE11Amplifier.get(), + std::make_unique(&theParameterMap, + theHBHEQIE11Amplifier.get(), theCoderFactory.get(), PreMix1); // should this use a different coder factory? From 768d39c706ed0c293ec0b0337b94112631730e2d Mon Sep 17 00:00:00 2001 From: Long Date: Mon, 4 Nov 2019 19:20:58 +0100 Subject: [PATCH 5/8] simplify qie11 header adding code and change local variable format --- .../plugins/HcalDigiToRawuHTR.cc | 3 +- .../HcalRawToDigi/plugins/PackerHelp.h | 77 ++++++++----------- SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc | 7 +- 3 files changed, 40 insertions(+), 47 deletions(-) diff --git a/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc b/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc index aec36482c37c1..552863b3456c5 100644 --- a/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc +++ b/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc @@ -146,12 +146,13 @@ void HcalDigiToRawuHTR::produce(edm::StreamID id, edm::Event& iEvent, const edm: // convert to hb qie data if hb if (HcalDetId(detid.rawId()).subdet() == HcalSubdetector::HcalBarrel) - qiedf = convertHB2HE(qiedf); + qiedf = convertHB(qiedf); if (!uhtrs.exist(uhtrIndex)) { uhtrs.newUHTR(uhtrIndex, presamples); } uhtrs.addChannel(uhtrIndex, qiedf, readoutMap, _verbosity); + // if(HcalDetId(qiedf.detid()).ieta()==1&&HcalDetId(qiedf.detid()).iphi()==1) std::cout<= 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_); + 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); - capid_ = qiehe[0].capid(); - qiehb.setCapid0(capid_); + capid = qiehe[0].capid(); + qiehb.setCapid0(capid); return qiehb; } diff --git a/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc b/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc index e969f6d11f197..a3f8ad79076dd 100644 --- a/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc +++ b/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc @@ -76,18 +76,19 @@ void HcalTDC::timing(const CaloSamples& lf, QIE11DataFrame& digi) const { digi.setSample(ibin, digi[ibin].adc(), packedTDC, digi[ibin].soi()); /*if ( hasTDCValues) { - if(HcalDetId(hcaldetid()).ieta()==1&&HcalDetId(hcaldetid()).iphi()==1){ - std::cout << " Depth: " << digi.hcaldetid().depth() + if(HcalDetId(digi.detid()).ieta()==1&&HcalDetId(digi.detid()).iphi()==1){ + std::cout << " Depth: " << HcalDetId(digi.detid()).depth() << " sample: " << ibin << " adc: " << digi[ibin].adc() << " capid: " << digi[ibin].capid() << " risingEdge: " << TDC_RisingEdge << " packedTDC: " << packedTDC << " tdc: " << digi[ibin].tdc() << " flavor(HE=0/HB=3): " << digi.flavor() - << " SubDet(HE=2/HB=1): " << digi.hcaldetid().subdet() + << " SubDet(HE=2/HB=1): " << HcalDetId(digi.detid()).subdet() << std::endl; } }*/ + // if(HcalDetId(digi.detid()).ieta()==1&&HcalDetId(digi.detid()).iphi()==1) std::cout< Date: Tue, 5 Nov 2019 07:28:08 +0100 Subject: [PATCH 6/8] remove commented test cout --- .../HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc | 1 - SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc | 16 ---------------- 2 files changed, 17 deletions(-) diff --git a/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc b/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc index 552863b3456c5..d637dab1192ba 100644 --- a/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc +++ b/EventFilter/HcalRawToDigi/plugins/HcalDigiToRawuHTR.cc @@ -152,7 +152,6 @@ void HcalDigiToRawuHTR::produce(edm::StreamID id, edm::Event& iEvent, const edm: uhtrs.newUHTR(uhtrIndex, presamples); } uhtrs.addChannel(uhtrIndex, qiedf, readoutMap, _verbosity); - // if(HcalDetId(qiedf.detid()).ieta()==1&&HcalDetId(qiedf.detid()).iphi()==1) std::cout< TDC_Threshold)) { TDC_RisingEdge = theTDCParameters.alreadyTransitionCode(); @@ -75,20 +73,6 @@ void HcalTDC::timing(const CaloSamples& lf, QIE11DataFrame& digi) const { int packedTDC = TDC_RisingEdge; digi.setSample(ibin, digi[ibin].adc(), packedTDC, digi[ibin].soi()); - /*if ( hasTDCValues) { - if(HcalDetId(digi.detid()).ieta()==1&&HcalDetId(digi.detid()).iphi()==1){ - std::cout << " Depth: " << HcalDetId(digi.detid()).depth() - << " sample: " << ibin << " adc: " << digi[ibin].adc() - << " capid: " << digi[ibin].capid() - << " risingEdge: " << TDC_RisingEdge - << " packedTDC: " << packedTDC - << " tdc: " << digi[ibin].tdc() - << " flavor(HE=0/HB=3): " << digi.flavor() - << " SubDet(HE=2/HB=1): " << HcalDetId(digi.detid()).subdet() - << std::endl; - } - }*/ - // if(HcalDetId(digi.detid()).ieta()==1&&HcalDetId(digi.detid()).iphi()==1) std::cout< Date: Tue, 5 Nov 2019 07:30:39 +0100 Subject: [PATCH 7/8] remove commented test cout --- SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc b/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc index 02e1f66046fcd..058e51680912d 100644 --- a/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc +++ b/SimCalorimetry/HcalSimAlgos/src/HcalTDC.cc @@ -18,8 +18,6 @@ void HcalTDC::timing(const CaloSamples& lf, QIE11DataFrame& digi) const { if (lf.preciseSize() == 0) hasTDCValues = false; - //std::cout << "TDC threshold: " << TDC_Threshold << std::endl; - for (int ibin = 0; ibin < lf.size(); ++ibin) { /* If in a given 25ns bunch/time sample, the pulse is above From 455061fcab290a572644d5b31405e5cca12c816c Mon Sep 17 00:00:00 2001 From: Long Date: Tue, 5 Nov 2019 11:06:24 +0100 Subject: [PATCH 8/8] simplify the code of unassigned variables --- EventFilter/HcalRawToDigi/plugins/PackerHelp.h | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/EventFilter/HcalRawToDigi/plugins/PackerHelp.h b/EventFilter/HcalRawToDigi/plugins/PackerHelp.h index 8a4ed4ba0b1dc..95973433bc6de 100644 --- a/EventFilter/HcalRawToDigi/plugins/PackerHelp.h +++ b/EventFilter/HcalRawToDigi/plugins/PackerHelp.h @@ -351,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; } @@ -418,13 +418,9 @@ class UHTRpacker { int fiber = eid.fiberIndex(); int fiberchan = eid.fiberChanId(); - // capacitor id for the first sample - int flavor = qiedf[0].flavor(); - int capid0; - if (qiedf.samples() == 0) - capid0 = 0; - else if (flavor == 3) { + + 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; @@ -432,7 +428,7 @@ class UHTRpacker { header |= (flavor & QIE11HeaderSpec3::MASK_FLAVOR) << QIE11HeaderSpec3::OFFSET_FLAVOR; //flavor header |= (0x1 & QIE11HeaderSpec3::MASK_HEADER_BIT) << QIE11HeaderSpec3::OFFSET_HEADER_BIT; } else { - capid0 = qiedf[0].capid(); + 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; @@ -622,7 +618,7 @@ class UHTRpacker { QIE11DataFrame convertHB(QIE11DataFrame qiehe) { QIE11DataFrame qiehb = qiehe; - int adc, tdc, capid; + int adc, tdc; bool soi; int is = 0; @@ -652,7 +648,7 @@ QIE11DataFrame convertHB(QIE11DataFrame qiehe) { // puting flavor is safe here because flavor is stored in the same bits for all flavors qiehb.setFlavor(hbflavor); - capid = qiehe[0].capid(); + int capid = qiehe[0].capid(); qiehb.setCapid0(capid); return qiehb;