diff --git a/CalibCalorimetry/EBPhase2TPGTools/BuildFile.xml b/CalibCalorimetry/EBPhase2TPGTools/BuildFile.xml new file mode 100644 index 0000000000000..07af00943a026 --- /dev/null +++ b/CalibCalorimetry/EBPhase2TPGTools/BuildFile.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/CalibCalorimetry/EBPhase2TPGTools/plugins/BuildFile.xml b/CalibCalorimetry/EBPhase2TPGTools/plugins/BuildFile.xml new file mode 100644 index 0000000000000..a9dd20350ca2f --- /dev/null +++ b/CalibCalorimetry/EBPhase2TPGTools/plugins/BuildFile.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/CalibCalorimetry/EBPhase2TPGTools/plugins/EcalEBPhase2TPParamProducer.cc b/CalibCalorimetry/EBPhase2TPGTools/plugins/EcalEBPhase2TPParamProducer.cc new file mode 100644 index 0000000000000..fee2d6b50f29e --- /dev/null +++ b/CalibCalorimetry/EBPhase2TPGTools/plugins/EcalEBPhase2TPParamProducer.cc @@ -0,0 +1,435 @@ +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/FileInPath.h" +// +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" +#include "Geometry/CaloGeometry/interface/CaloCellGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h" +#include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h" +#include "Geometry/EcalMapping/interface/EcalMappingRcd.h" +#include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h" +#include "CondFormats/EcalObjects/interface/EcalLiteDTUPedestals.h" +#include "CondFormats/DataRecord/interface/EcalLiteDTUPedestalsRcd.h" +#include "DataFormats/EcalDigi/interface/EcalConstants.h" +#include "DataFormats/EcalDetId/interface/EcalSubdetector.h" +#include "DataFormats/EcalDetId/interface/EBDetId.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/** +\class EcalEBPhase2TPParamProducer +\author L. Lutton, N. Marinelli - Univ. of Notre Dame +\brief TPG Param Builder for Phase2 +*/ + +class EcalEBPhase2TPParamProducer : public edm::one::EDAnalyzer<> { +public: + explicit EcalEBPhase2TPParamProducer(edm::ParameterSet const& pSet); + ~EcalEBPhase2TPParamProducer() override; + void analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) override; + void beginJob() override; + static void fillDescriptions(edm::ConfigurationDescriptions&); + +private: + std::vector computeWeights(int type); + + void getNumericalDeriv(TGraph graph, TGraph& deriv); + void fillFMat(std::vector clockSampleSet, + bool useThirdPulse, + std::vector sampleSet, + std::vector sampleDotSet, + TMatrix& FMat, + unsigned int binOfMaximum); + void getGMatrix(TMatrix FMat, float scaleMatrixBy, TMatrix& GMat); + void getPulseSampleSet(TGraph pulseGraph, float phaseShift, std::vector& sampleSet); + bool computeLinearizerParam(double theta, double gainRatio, double calibCoeff, int& shift, int& mult); + + const edm::ESGetToken theBarrelGeometryToken_; + const edm::FileInPath inFile_; + const std::string outFile_; + const int nSamplesToUse_; + const bool useBXPlusOne_; + const double phaseShift_; + const unsigned int nWeightGroups_; + const edm::ESGetToken theEcalTPGPedestals_Token_; + + gzFile out_file_; + TGraph* thePulse_; + TGraph* pulseDot_; + + const UInt_t NPoints_ = 1599; //With the CMSSW pulse + + static constexpr float norm_ = 1 / 503.109; // with the CMSSW pulse shape + static constexpr float offset_ = 0.; // with the CMSSW pulse shape + int multToInt_ = 0x1000; + + int i2cSub_[2] = {0, 0}; + + const double et_sat_; + const double xtal_LSB_; + const unsigned int binOfMaximum_; + static const int linTopRange_; +}; + +EcalEBPhase2TPParamProducer::EcalEBPhase2TPParamProducer(edm::ParameterSet const& pSet) + : theBarrelGeometryToken_(esConsumes(edm::ESInputTag("", "EcalBarrel"))), + inFile_(pSet.getParameter("inputFile")), + outFile_(pSet.getUntrackedParameter("outputFile")), + nSamplesToUse_(pSet.getParameter("nSamplesToUse")), + useBXPlusOne_(pSet.getParameter("useBXPlusOne")), + phaseShift_(pSet.getParameter("phaseShift")), + nWeightGroups_(pSet.getParameter("nWeightGroups")), + theEcalTPGPedestals_Token_(esConsumes(edm::ESInputTag("EcalLiteDTUPedestals", ""))), + et_sat_(pSet.getParameter("Et_sat")), + xtal_LSB_(pSet.getParameter("xtal_LSB")), + binOfMaximum_(pSet.getParameter("binOfMaximum")) + +{ + out_file_ = gzopen(outFile_.c_str(), "wb"); + + std::string filename = inFile_.fullPath(); + TFile* inFile = new TFile(filename.c_str(), "READ"); + + inFile->GetObject("average-pulse", thePulse_); + delete inFile; + + if (binOfMaximum_ != 6 && binOfMaximum_ != 8) + edm::LogError("EcalEBPhase2TPParamProducer") + << " Value for binOfMaximum " << binOfMaximum_ << " is wrong, The default binOfMaximum=6 will be used"; + + if (nSamplesToUse_ != 6 && nSamplesToUse_ != 8 && nSamplesToUse_ != 12) + edm::LogError("EcalEBPhase2TPParamProducer") + << " Value for nSamplesToUse " << nSamplesToUse_ << " is wrong, The default nSamplesToUse=8 will be used"; +} + +EcalEBPhase2TPParamProducer::~EcalEBPhase2TPParamProducer() { gzclose(out_file_); } + +void EcalEBPhase2TPParamProducer::beginJob() {} + +void EcalEBPhase2TPParamProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("inputFile"); + desc.addUntracked("outputFile"); + desc.add("nSamplesToUse", 8); + desc.add("useBXPlusOne", false); + desc.add("phaseShift", 2.581); + desc.add("nWeightGroups", 61200); + desc.add("Et_sat", 1998.36); + desc.add("xtal_LSB", 0.0488); + desc.add("binOfMaximum", 6); + descriptions.add("ecalEBPhase2TPParamProducerDefault", desc); +} + +void EcalEBPhase2TPParamProducer::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) { + using namespace edm; + using namespace std; + + const EcalLiteDTUPedestals* peds = nullptr; + const auto* theBarrelGeometry = &evtSetup.getData(theBarrelGeometryToken_); + const auto* theEcalTPPedestals = &evtSetup.getData(theEcalTPGPedestals_Token_); + + std::string tmpStringConv; + const char* tmpStringOut; + + // Compute weights // + std::vector ampWeights[nWeightGroups_]; + std::vector timeWeights[nWeightGroups_]; + + for (unsigned int iGr = 0; iGr < nWeightGroups_; iGr++) { + ampWeights[iGr] = computeWeights(1); + timeWeights[iGr] = computeWeights(2); + } + + /* write to compressed file */ + std::stringstream toCompressStream(""); + for (unsigned int iGr = 0; iGr < nWeightGroups_; iGr++) { + toCompressStream << " WEIGHTAMP " << dec << iGr << std::endl; + for (long unsigned int i = 0; i < ampWeights[iGr].size(); i++) { + if (ampWeights[iGr][i] < 0) + toCompressStream << "-0x" << std::hex << abs(ampWeights[iGr][i]) << " "; + else + toCompressStream << "0x" << std::hex << ampWeights[iGr][i] << " "; + } + toCompressStream << "\n"; + } + toCompressStream << "\n"; + tmpStringConv = toCompressStream.str(); + tmpStringOut = tmpStringConv.c_str(); + gzwrite(out_file_, tmpStringOut, std::strlen(tmpStringOut)); + toCompressStream.str(std::string()); + + for (unsigned int iGr = 0; iGr < nWeightGroups_; iGr++) { + toCompressStream << "WEIGHTTIME " << dec << iGr << std::endl; + for (long unsigned int i = 0; i < timeWeights[iGr].size(); i++) { + if (timeWeights[iGr][i] < 0) + toCompressStream << "-0x" << std::hex << abs(timeWeights[iGr][i]) << " "; + else + toCompressStream << "0x" << std::hex << timeWeights[iGr][i] << " "; + } + toCompressStream << "\n"; + } + + toCompressStream << "\n"; + tmpStringConv = toCompressStream.str(); + tmpStringOut = tmpStringConv.c_str(); + gzwrite(out_file_, tmpStringOut, std::strlen(tmpStringOut)); + toCompressStream.str(std::string()); + + // fill map between xTals and groups. If each xTal is a group there is a one-to-one map + const std::vector& ebCells = theBarrelGeometry->getValidDetIds(DetId::Ecal, EcalBarrel); + std::map mapXtalToGroup; + + int iGroup = 0; + for (const auto& it : ebCells) { + EBDetId id(it); + std::pair xTalToGroup(id.rawId(), iGroup); + mapXtalToGroup.insert(xTalToGroup); + iGroup++; + } + + //write to file + + for (std::map::const_iterator it = mapXtalToGroup.begin(); it != mapXtalToGroup.end(); it++) { + toCompressStream << "CRYSTAL " << dec << it->first << std::endl; + toCompressStream << it->second << std::endl; + } + tmpStringConv = toCompressStream.str(); + tmpStringOut = tmpStringConv.c_str(); + gzwrite(out_file_, tmpStringOut, std::strlen(tmpStringOut)); + toCompressStream.str(std::string()); + + ///////////////////////////////////// + + for (const auto& it : ebCells) { + EBDetId id(it); + toCompressStream << "LINCONST " << dec << id.rawId() << std::endl; + double theta = theBarrelGeometry->getGeometry(id)->getPosition().theta(); + EcalLiteDTUPedestalsMap::const_iterator itped = theEcalTPPedestals->getMap().find(id); + + if (itped != theEcalTPPedestals->end()) { + peds = &(*itped); + + } else { + edm::LogError("EcalEBPhase2TPParamProducer") << " could not find EcalLiteDTUPedestal entry for " << id; + throw cms::Exception("could not find pedestals"); + } + + int shift, mult; + double calibCoeff = 1.; + bool ok; + for (unsigned int i = 0; i < ecalPh2::NGAINS; ++i) { + ok = computeLinearizerParam(theta, ecalph2::gains[ecalPh2::NGAINS - 1 - i], calibCoeff, shift, mult); + if (!ok) { + edm::LogError("EcalEBPhase2TPParamProducer") + << "unable to compute the parameters for SM=" << id.ism() << " xt=" << id.ic() << " " << id.rawId(); + throw cms::Exception("unable to compute the parameters"); + + } else { + int tmpPedByGain = (int)(peds->mean(i) + 0.5); + toCompressStream << std::hex << " 0x" << tmpPedByGain << " 0x" << mult << " 0x" << shift << " " << i2cSub_[i] + << std::endl; + } + } + } + tmpStringConv = toCompressStream.str(); + tmpStringOut = tmpStringConv.c_str(); + gzwrite(out_file_, tmpStringOut, std::strlen(tmpStringOut)); + toCompressStream.str(std::string()); +} + +std::vector EcalEBPhase2TPParamProducer::computeWeights(int type) { + std::vector sampleSet; + std::vector sampleDotSet; + std::vector clockSampleSet; + double scaleMatrixBy = 1.; + int lbinOfMaximum = binOfMaximum_; + + switch (binOfMaximum_) { + case 6: + break; + case 8: + break; + default: + lbinOfMaximum = 6; + break; + } + + switch (nSamplesToUse_) { + case 12: + clockSampleSet = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + break; + case 8: + switch (lbinOfMaximum) { + case 8: + clockSampleSet = {2, 3, 4, 5, 6, 7, 8, 9}; + break; + case 6: + clockSampleSet = {0, 1, 2, 3, 4, 5, 6, 7}; + break; + } + break; + + case 6: + switch (lbinOfMaximum) { + case 8: + clockSampleSet = {3, 4, 6, 7, 8, 9}; + break; + case 6: + clockSampleSet = {1, 2, 4, 5, 6, 7}; + break; + } + break; + + default: + clockSampleSet = {0, 1, 2, 3, 4, 5, 6, 7}; + break; + } + + getPulseSampleSet(*thePulse_, phaseShift_, sampleSet); + pulseDot_ = new TGraph(); + getNumericalDeriv(*thePulse_, *pulseDot_); + getPulseSampleSet(*pulseDot_, phaseShift_, sampleDotSet); + + unsigned int fMatColumns = useBXPlusOne_ ? 6 : 4; + + TMatrix fMat(clockSampleSet.size(), fMatColumns); + fillFMat(clockSampleSet, useBXPlusOne_, sampleSet, sampleDotSet, fMat, lbinOfMaximum); + TMatrix gMat(fMatColumns, clockSampleSet.size()); + + getGMatrix(fMat, scaleMatrixBy, gMat); + + std::vector tmpWeightVec; + std::vector tmpTimeWeightVec; + unsigned int iClock = 0; + for (unsigned int iSample = 0; iSample < 12; iSample++) { + bool inSampleSet = false; + for (unsigned int clockSample = 0; clockSample < clockSampleSet.size(); clockSample++) { + if (iSample == clockSampleSet[clockSample]) { + inSampleSet = true; + iClock = clockSample; + break; + } + } + if (inSampleSet) { + if (type == 1) + tmpWeightVec.push_back(round(gMat(2, iClock) * multToInt_)); // amp weights + if (type == 2) + tmpWeightVec.push_back(round(gMat(3, iClock) * multToInt_)); // time weights + } else { + if (type == 1) + tmpWeightVec.push_back(0); // amp weights + if (type == 2) + tmpWeightVec.push_back(0); // time weights + } + } + + return tmpWeightVec; +} + +void EcalEBPhase2TPParamProducer::getNumericalDeriv(TGraph graph, TGraph& deriv) { + UInt_t numPoints = graph.GetN(); + if (numPoints != NPoints_) { + edm::LogWarning("EcalEBPhase2TPParamProducer") << "Error! Wrong amount of points in pulse graph! "; + } + Double_t xval; + Double_t yval; + Double_t xvalPOne; + Double_t yvalPOne; + + for (UInt_t p = 0; p < NPoints_ - 1; p++) { + graph.GetPoint(p, xval, yval); + graph.GetPoint(p + 1, xvalPOne, yvalPOne); + float midpoint = (xvalPOne + xval) / 2; + float rise = yvalPOne - yval; + float run = xvalPOne - xval; + deriv.SetPoint(deriv.GetN(), midpoint, rise / run); + } + deriv.SetName("pulse_prime"); +} + +void EcalEBPhase2TPParamProducer::fillFMat(std::vector clockSampleSet, + bool useThirdPulse, + std::vector sampleSet, + std::vector sampleDotSet, + TMatrix& fMat, + uint binOfMaximum) { + Int_t iShift = 8 - binOfMaximum; + for (UInt_t i = 0; i < clockSampleSet.size(); i++) { + Int_t tmpClockToSample = clockSampleSet[i] + iShift; + fMat(i, 0) = sampleSet[tmpClockToSample]; + fMat(i, 1) = sampleDotSet[tmpClockToSample]; + if (tmpClockToSample > 4) { + fMat(i, 2) = sampleSet[tmpClockToSample - 4]; + fMat(i, 3) = sampleDotSet[tmpClockToSample - 4]; + } + if (clockSampleSet[i] > 8 && useThirdPulse) { + fMat(i, 4) = sampleSet[tmpClockToSample - 8]; + fMat(i, 5) = sampleDotSet[tmpClockToSample - 8]; + } + } +} + +void EcalEBPhase2TPParamProducer::getGMatrix(TMatrix fMat, float scaleMatrixBy, TMatrix& gMat) { + TMatrix FT = fMat; + FT.T(); + TMatrix tmpFT = FT; + TMatrix FTDotF = TMatrix(tmpFT, TMatrix::kMult, fMat); + TMatrix InvFTDotF = FTDotF; + + //Possible for this bit to fail depending on the sample set and phase shift + InvFTDotF.Invert(); + + TMatrix tmpMat(InvFTDotF, TMatrix::kMult, FT); + gMat = tmpMat; + gMat *= scaleMatrixBy; +} + +void EcalEBPhase2TPParamProducer::getPulseSampleSet(TGraph pulseGraph, + float phaseShift, + std::vector& sampleSet) { + for (UInt_t i = 0; i < ecalPh2::sampleSize; i++) { + float t = (ecalPh2::Samp_Period * i) + phaseShift; + float y = pulseGraph.Eval(t + offset_) * norm_; + sampleSet.push_back(y); + } +} + +bool EcalEBPhase2TPParamProducer::computeLinearizerParam( + double theta, double gainRatio, double calibCoeff, int& shift, int& mult) { + bool result = false; + + static constexpr double linTopRange_ = 16383.; + // linTopRange_ 16383 = (2**14)-1 is setting the top of the range for the linearizer output + double factor = (linTopRange_ * (xtal_LSB_ * gainRatio * calibCoeff * sin(theta))) / et_sat_; + //first with shift_ = 0 + //add 0.5 (for rounding) and set to int + //Here we are getting mult with a max bit length of 8 + //and shift_ with a max bit length of 4 + mult = (int)(factor + 0.5); + for (shift = 0; shift < 15; shift++) { + if (mult >= 128 && mult < 256) { + result = true; + break; + } + factor *= 2; + mult = (int)(factor + 0.5); + } + + return result; +} + +// DEfine this module as a plug-in +DEFINE_FWK_MODULE(EcalEBPhase2TPParamProducer); diff --git a/CalibCalorimetry/EBPhase2TPGTools/python/ecalEBPhase2TPParamProducer_cfi.py b/CalibCalorimetry/EBPhase2TPGTools/python/ecalEBPhase2TPParamProducer_cfi.py new file mode 100644 index 0000000000000..1faa813593464 --- /dev/null +++ b/CalibCalorimetry/EBPhase2TPGTools/python/ecalEBPhase2TPParamProducer_cfi.py @@ -0,0 +1,24 @@ +import FWCore.ParameterSet.Config as cms + +EBPhase2TPGParamProducer = cms.EDAnalyzer("EcalEBPhase2TPParamProducer", +inputFile = cms.FileInPath('SimCalorimetry/EcalEBTrigPrimProducers/data/CMSSWPhaseIIPulseGraphAlt.root'), +outputFile = cms.untracked.string('../../../SimCalorimetry/EcalEBTrigPrimProducers/data/AmpTimeOnPeakXtalWeightsCMSSWPulse_8samples_peakOnSix_WithAndyFixes.txt.gz'), + nSamplesToUse = cms.uint32(8), + useBXPlusOne = cms.bool(False), + phaseShift = cms.double (2.581), + nWeightGroups = cms.uint32(61200), + Et_sat = cms.double(1998.36), + xtal_LSB = cms.double(0.0488), + binOfMaximum = cms.uint32(6) + + +## allowed values of nSamplesToUse: 12, 8, 6. nSamplesToUse=8 is the default +## allowed values of binOfMaximum: 6, 8. binOfMaximum=6 is the default +#### The DEFAULT is nSamplesToUse=8, binOfMaximum=6 ####### + +## If nSamplesToUse is 12 ==> useBXPlusOne is True +## If nSamplesToUse is 8 ==> useBXPlusOne is False +## If nSamplesToUse is 6 ==> useBXPlusOne is False + +) + diff --git a/CalibCalorimetry/EBPhase2TPGTools/test/runEBPhase2TPParamProducer.py b/CalibCalorimetry/EBPhase2TPGTools/test/runEBPhase2TPParamProducer.py new file mode 100644 index 0000000000000..eea149b2c2029 --- /dev/null +++ b/CalibCalorimetry/EBPhase2TPGTools/test/runEBPhase2TPParamProducer.py @@ -0,0 +1,91 @@ +import FWCore.ParameterSet.Config as cms +import CondTools.Ecal.db_credentials as auth +import FWCore.ParameterSet.VarParsing as VarParsing + + +from Configuration.Eras.Era_Phase2C17I13M9_cff import Phase2C17I13M9 +from Configuration.Eras.Modifier_phase2_ecal_devel_cff import phase2_ecal_devel + + +#process = cms.Process("ProdTPGParam") +process = cms.Process('DIGI',Phase2C17I13M9,phase2_ecal_devel) + +process.load('Configuration.StandardSequences.Services_cff') +process.load('SimGeneral.HepPDTESSource.pythiapdt_cfi') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.EventContent.EventContent_cff') +process.load('SimGeneral.MixingModule.mixNoPU_cfi') +process.load('Configuration.Geometry.GeometryExtended2026D88Reco_cff') +process.load('Configuration.Geometry.GeometryExtended2026D88_cff') +process.load('Configuration.StandardSequences.MagneticField_cff') +process.load('Configuration.StandardSequences.Generator_cff') +process.load('IOMC.EventVertexGenerators.VtxSmearedHLLHC14TeV_cfi') +process.load('GeneratorInterface.Core.genFilterSummary_cff') +process.load('Configuration.StandardSequences.SimIdeal_cff') +process.load('Configuration.StandardSequences.Digi_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +#process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') TO BE FIXED +process.load('CalibCalorimetry.EBPhase2TPGTools.ecalEBPhase2TPParamProducer_cfi') +""" +options = VarParsing.VarParsing('tpg') + +options.register ('outFile', + 'testtest.txt', + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.string, + "Output file") + +options.parseArguments() +""" +# Calo geometry service model +#process.load("Configuration.StandardSequences.GeometryDB_cff") + +# ecal mapping +process.eegeom = cms.ESSource("EmptyESSource", + recordName = cms.string('EcalMappingRcd'), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(1) +) + +# Get hardcoded conditions the same used for standard digitization before CMSSW_3_1_x +## process.load("CalibCalorimetry.EcalTrivialCondModules.EcalTrivialCondRetriever_cfi") +# or Get DB parameters +# process.load('Configuration/StandardSequences/FrontierConditions_GlobalTag_cff') +process.load("CondCore.CondDB.CondDB_cfi") + +process.CondDB.connect = 'frontier://FrontierProd/CMS_CONDITIONS' +process.CondDB.DBParameters.authenticationPath = '/nfshome0/popcondev/conddb' ###P5 stuff + +""" +process.PoolDBESSource = cms.ESSource("PoolDBESSource", + process.CondDB, + timetype = cms.untracked.string('runnumber'), + toGet = cms.VPSet( + cms.PSet( + record = cms.string('EcalPedestalsRcd'), + #tag = cms.string('EcalPedestals_v5_online') + #tag = cms.string('EcalPedestals_2009runs_hlt') ### obviously diff w.r.t previous + tag = cms.string('EcalPedestals_hlt'), ### modif-alex 22/02/2011 + ), + cms.PSet( + record = cms.string('EcalMappingElectronicsRcd'), + tag = cms.string('EcalMappingElectronics_EEMap_v1_mc') + ) + ) + ) +""" + +######################### +process.source = cms.Source("EmptySource", + ##firstRun = cms.untracked.uint32(100000000) ### need to use latest run to pick-up update values from DB + firstRun = cms.untracked.uint32(161310) +) + + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(1) +) + + + +process.p = cms.Path(process.EBPhase2TPGParamProducer) diff --git a/CondCore/Utilities/plugins/Module_2XML.cc b/CondCore/Utilities/plugins/Module_2XML.cc index 09e00aebbc052..bd0bcc61e92f4 100644 --- a/CondCore/Utilities/plugins/Module_2XML.cc +++ b/CondCore/Utilities/plugins/Module_2XML.cc @@ -115,6 +115,12 @@ PAYLOAD_2XML_MODULE(pluginUtilities_payload2xml) { PAYLOAD_2XML_CLASS(EcalTPGOddWeightGroup); PAYLOAD_2XML_CLASS(EcalTPGOddWeightIdMap); PAYLOAD_2XML_CLASS(EcalTPGTPMode); + PAYLOAD_2XML_CLASS(EcalEBPhase2TPGAmplWeightIdMap); + PAYLOAD_2XML_CLASS(EcalEBPhase2TPGAmplWeights); + PAYLOAD_2XML_CLASS(EcalEBPhase2TPGLinearizationConstant); + PAYLOAD_2XML_CLASS(EcalEBPhase2TPGPedestal); + PAYLOAD_2XML_CLASS(EcalEBPhase2TPGTimeWeightIdMap); + PAYLOAD_2XML_CLASS(EcalEBPhase2TPGTimeWeights); PAYLOAD_2XML_CLASS(EcalTimeBiasCorrections); PAYLOAD_2XML_CLASS(EcalTimeDependentCorrections); PAYLOAD_2XML_CLASS(EcalTimeOffsetConstant); diff --git a/CondCore/Utilities/src/CondDBFetch.cc b/CondCore/Utilities/src/CondDBFetch.cc index f82f1fae959b0..05f231dab8dec 100644 --- a/CondCore/Utilities/src/CondDBFetch.cc +++ b/CondCore/Utilities/src/CondDBFetch.cc @@ -145,6 +145,12 @@ namespace cond { FETCH_PAYLOAD_CASE(EcalPulseCovariance) FETCH_PAYLOAD_CASE(EcalCondObjectContainer) FETCH_PAYLOAD_CASE(EcalPulseSymmCovariance) + FETCH_PAYLOAD_CASE(EcalEBPhase2TPGAmplWeightIdMap) + FETCH_PAYLOAD_CASE(EcalEBPhase2TPGAmplWeights) + FETCH_PAYLOAD_CASE(EcalEBPhase2TPGTimeWeightIdMap) + FETCH_PAYLOAD_CASE(EcalEBPhase2TPGTimeWeights) + FETCH_PAYLOAD_CASE(EcalEBPhase2TPGLinearizationConstant) + FETCH_PAYLOAD_CASE(EcalEBPhase2TPGPedestal) FETCH_PAYLOAD_CASE(FileBlob) FETCH_PAYLOAD_CASE(GBRForest) FETCH_PAYLOAD_CASE(GBRForestD) diff --git a/CondCore/Utilities/src/CondDBImport.cc b/CondCore/Utilities/src/CondDBImport.cc index a35f61600a67c..1d938599159bb 100644 --- a/CondCore/Utilities/src/CondDBImport.cc +++ b/CondCore/Utilities/src/CondDBImport.cc @@ -165,6 +165,12 @@ namespace cond { IMPORT_PAYLOAD_CASE(EcalPulseCovariance) IMPORT_PAYLOAD_CASE(EcalCondObjectContainer) IMPORT_PAYLOAD_CASE(EcalPulseSymmCovariance) + IMPORT_PAYLOAD_CASE(EcalEBPhase2TPGAmplWeightIdMap) + IMPORT_PAYLOAD_CASE(EcalEBPhase2TPGAmplWeights) + IMPORT_PAYLOAD_CASE(EcalEBPhase2TPGTimeWeightIdMap) + IMPORT_PAYLOAD_CASE(EcalEBPhase2TPGTimeWeights) + IMPORT_PAYLOAD_CASE(EcalEBPhase2TPGPedestal) + IMPORT_PAYLOAD_CASE(EcalEBPhase2TPGLinearizationConstant) IMPORT_PAYLOAD_CASE(FileBlob) IMPORT_PAYLOAD_CASE(GBRForest) IMPORT_PAYLOAD_CASE(GBRForestD) diff --git a/CondCore/Utilities/src/CondFormats.h b/CondCore/Utilities/src/CondFormats.h index c35957099e6d4..f5c858609478b 100644 --- a/CondCore/Utilities/src/CondFormats.h +++ b/CondCore/Utilities/src/CondFormats.h @@ -72,6 +72,12 @@ #include "CondFormats/EcalObjects/interface/EcalPulseShapes.h" #include "CondFormats/EcalObjects/interface/EcalPulseCovariances.h" #include "CondFormats/EcalObjects/interface/EcalPulseSymmCovariances.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeightIdMap.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeights.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGLinearizationConst.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGPedestals.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeightIdMap.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeights.h" #include "CondFormats/GBRForest/interface/GBRForest.h" #include "CondFormats/GBRForest/interface/GBRForestD.h" #include "CondFormats/HcalObjects/interface/AbsOOTPileupCorrection.h" diff --git a/CondFormats/DataRecord/interface/EcalEBPhase2TPGAmplWeightIdMapRcd.h b/CondFormats/DataRecord/interface/EcalEBPhase2TPGAmplWeightIdMapRcd.h new file mode 100644 index 0000000000000..a9389ef6367a3 --- /dev/null +++ b/CondFormats/DataRecord/interface/EcalEBPhase2TPGAmplWeightIdMapRcd.h @@ -0,0 +1,7 @@ +#ifndef CondFormats_DataRecord_EcalEBPhase2TPGAmplWeightIdMapRcd_h +#define CondFormats_DataRecord_EcalEBPhase2TPGAmplWeightIdMapRcd_h + +#include "FWCore/Framework/interface/EventSetupRecordImplementation.h" +class EcalEBPhase2TPGAmplWeightIdMapRcd + : public edm::eventsetup::EventSetupRecordImplementation {}; +#endif diff --git a/CondFormats/DataRecord/interface/EcalEBPhase2TPGLinearizationConstRcd.h b/CondFormats/DataRecord/interface/EcalEBPhase2TPGLinearizationConstRcd.h new file mode 100644 index 0000000000000..8cae9d31c7d27 --- /dev/null +++ b/CondFormats/DataRecord/interface/EcalEBPhase2TPGLinearizationConstRcd.h @@ -0,0 +1,7 @@ +#ifndef CondFormats_DataRecord_EcalEBPhase2TPGLinearizationConstRcd_h +#define CondFormats_DataRecord_EcalEBPhase2TPGLinearizationConstRcd_h + +#include "FWCore/Framework/interface/EventSetupRecordImplementation.h" +class EcalEBPhase2TPGLinearizationConstRcd + : public edm::eventsetup::EventSetupRecordImplementation {}; +#endif diff --git a/CondFormats/DataRecord/interface/EcalEBPhase2TPGPedestalsRcd.h b/CondFormats/DataRecord/interface/EcalEBPhase2TPGPedestalsRcd.h new file mode 100644 index 0000000000000..399e780144b4a --- /dev/null +++ b/CondFormats/DataRecord/interface/EcalEBPhase2TPGPedestalsRcd.h @@ -0,0 +1,7 @@ +#ifndef CondFormats_DataRecord_EcalEBPhase2TPGPedestalsRcd_h +#define CondFormats_DataRecord_EcalEBPhase2TPGPedestalsRcd_h + +#include "FWCore/Framework/interface/EventSetupRecordImplementation.h" +class EcalEBPhase2TPGPedestalsRcd + : public edm::eventsetup::EventSetupRecordImplementation {}; +#endif diff --git a/CondFormats/DataRecord/interface/EcalEBPhase2TPGTimeWeightIdMapRcd.h b/CondFormats/DataRecord/interface/EcalEBPhase2TPGTimeWeightIdMapRcd.h new file mode 100644 index 0000000000000..7e591ffe19a73 --- /dev/null +++ b/CondFormats/DataRecord/interface/EcalEBPhase2TPGTimeWeightIdMapRcd.h @@ -0,0 +1,7 @@ +#ifndef CondFormats_DataRecord_EcalEBPhase2TPGTimeWeightIdMapRcd_h +#define CondFormats_DataRecord_EcalEBPhase2TPGTimeWeightIdMapRcd_h + +#include "FWCore/Framework/interface/EventSetupRecordImplementation.h" +class EcalEBPhase2TPGTimeWeightIdMapRcd + : public edm::eventsetup::EventSetupRecordImplementation {}; +#endif diff --git a/CondFormats/DataRecord/src/EcalEBPhase2TPGAmplWeightIdMapRcd.cc b/CondFormats/DataRecord/src/EcalEBPhase2TPGAmplWeightIdMapRcd.cc new file mode 100644 index 0000000000000..e6527eed26d8c --- /dev/null +++ b/CondFormats/DataRecord/src/EcalEBPhase2TPGAmplWeightIdMapRcd.cc @@ -0,0 +1,4 @@ +#include "CondFormats/DataRecord/interface/EcalEBPhase2TPGAmplWeightIdMapRcd.h" +#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h" + +EVENTSETUP_RECORD_REG(EcalEBPhase2TPGAmplWeightIdMapRcd); diff --git a/CondFormats/DataRecord/src/EcalEBPhase2TPGLinearizationConstRcd.cc b/CondFormats/DataRecord/src/EcalEBPhase2TPGLinearizationConstRcd.cc new file mode 100644 index 0000000000000..9e310ae324038 --- /dev/null +++ b/CondFormats/DataRecord/src/EcalEBPhase2TPGLinearizationConstRcd.cc @@ -0,0 +1,4 @@ +#include "CondFormats/DataRecord/interface/EcalEBPhase2TPGLinearizationConstRcd.h" +#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h" + +EVENTSETUP_RECORD_REG(EcalEBPhase2TPGLinearizationConstRcd); diff --git a/CondFormats/DataRecord/src/EcalEBPhase2TPGPedestalsRcd.cc b/CondFormats/DataRecord/src/EcalEBPhase2TPGPedestalsRcd.cc new file mode 100644 index 0000000000000..4d0beedfc9bdf --- /dev/null +++ b/CondFormats/DataRecord/src/EcalEBPhase2TPGPedestalsRcd.cc @@ -0,0 +1,4 @@ +#include "CondFormats/DataRecord/interface/EcalEBPhase2TPGPedestalsRcd.h" +#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h" + +EVENTSETUP_RECORD_REG(EcalEBPhase2TPGPedestalsRcd); diff --git a/CondFormats/DataRecord/src/EcalEBPhase2TPGTimeWeightIdMapRcd.cc b/CondFormats/DataRecord/src/EcalEBPhase2TPGTimeWeightIdMapRcd.cc new file mode 100644 index 0000000000000..1320e879c861f --- /dev/null +++ b/CondFormats/DataRecord/src/EcalEBPhase2TPGTimeWeightIdMapRcd.cc @@ -0,0 +1,4 @@ +#include "CondFormats/DataRecord/interface/EcalEBPhase2TPGTimeWeightIdMapRcd.h" +#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h" + +EVENTSETUP_RECORD_REG(EcalEBPhase2TPGTimeWeightIdMapRcd); diff --git a/CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeightIdMap.h b/CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeightIdMap.h new file mode 100644 index 0000000000000..ee5a3fdb3b02c --- /dev/null +++ b/CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeightIdMap.h @@ -0,0 +1,27 @@ +#ifndef CondFormats_EcalObjects_EcalEBPhase2TPGAmplWeightIdMap_h +#define CondFormats_EcalObjects_EcalEBPhase2TPGAmplWeightIdMap_h + +#include "CondFormats/Serialization/interface/Serializable.h" + +#include +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeights.h" +#include + +class EcalEBPhase2TPGAmplWeightIdMap { +public: + typedef std::map EcalEBPhase2TPGAmplWeightMap; + typedef std::map::const_iterator EcalEBPhase2TPGAmplWeightMapItr; + + EcalEBPhase2TPGAmplWeightIdMap(){}; + ~EcalEBPhase2TPGAmplWeightIdMap(){}; + + const EcalEBPhase2TPGAmplWeightMap& getMap() const { return map_; } + void setValue(const uint32_t& id, const EcalEBPhase2TPGAmplWeights& value); + +private: + EcalEBPhase2TPGAmplWeightMap map_; + + COND_SERIALIZABLE; +}; + +#endif diff --git a/CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeights.h b/CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeights.h new file mode 100644 index 0000000000000..3352099f69bf4 --- /dev/null +++ b/CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeights.h @@ -0,0 +1,56 @@ +#ifndef CondFormats_EcalObjects_EcalEBPhase2TPGAmplWeights_h +#define CondFormats_EcalObjects_EcalEBPhase2TPGAmplWeights_h + +#include "CondFormats/Serialization/interface/Serializable.h" + +#include +#include + +class EcalEBPhase2TPGAmplWeights { +public: + EcalEBPhase2TPGAmplWeights(); + ~EcalEBPhase2TPGAmplWeights(); + + void getValues(uint32_t& w0, + uint32_t& w1, + uint32_t& w2, + uint32_t& w3, + uint32_t& w4, + uint32_t& w5, + uint32_t& w6, + uint32_t& w7, + uint32_t& w8, + uint32_t& w9, + uint32_t& w10, + uint32_t& w11) const; + void setValues(const uint32_t& w0, + const uint32_t& w1, + const uint32_t& w2, + const uint32_t& w3, + const uint32_t& w4, + const uint32_t& w5, + const uint32_t& w6, + const uint32_t& w7, + const uint32_t& w8, + const uint32_t& w9, + const uint32_t& w10, + const uint32_t& w11); + +private: + uint32_t w0_; + uint32_t w1_; + uint32_t w2_; + uint32_t w3_; + uint32_t w4_; + uint32_t w5_; + uint32_t w6_; + uint32_t w7_; + uint32_t w8_; + uint32_t w9_; + uint32_t w10_; + uint32_t w11_; + + COND_SERIALIZABLE; +}; + +#endif diff --git a/CondFormats/EcalObjects/interface/EcalEBPhase2TPGLinearizationConst.h b/CondFormats/EcalObjects/interface/EcalEBPhase2TPGLinearizationConst.h new file mode 100644 index 0000000000000..68813c46aa63f --- /dev/null +++ b/CondFormats/EcalObjects/interface/EcalEBPhase2TPGLinearizationConst.h @@ -0,0 +1,27 @@ +#ifndef CondFormats_EcalObjects_EcalEBPhase2TPGLinearizationConst_h +#define CondFormats_EcalObjects_EcalEBPhase2TPGLinearizationConst_h + +#include "CondFormats/Serialization/interface/Serializable.h" + +#include "CondFormats/EcalObjects/interface/EcalCondObjectContainer.h" + +struct EcalEBPhase2TPGLinearizationConstant { + EcalEBPhase2TPGLinearizationConstant() + : mult_x10(0), mult_x1(0), shift_x10(0), shift_x1(0), i2cSub_x10(0), i2cSub_x1(0) {} + + uint32_t mult_x10; + uint32_t mult_x1; + uint32_t shift_x10; + uint32_t shift_x1; + uint32_t i2cSub_x10; + uint32_t i2cSub_x1; + + COND_SERIALIZABLE; +}; + +typedef EcalCondObjectContainer EcalEBPhase2TPGLinearizationConstMap; +typedef EcalCondObjectContainer::const_iterator + EcalEBPhase2TPGLinearizationConstMapIterator; +typedef EcalEBPhase2TPGLinearizationConstMap EcalEBPhase2TPGLinearizationConst; + +#endif diff --git a/CondFormats/EcalObjects/interface/EcalEBPhase2TPGPedestals.h b/CondFormats/EcalObjects/interface/EcalEBPhase2TPGPedestals.h new file mode 100644 index 0000000000000..918fa6727f16b --- /dev/null +++ b/CondFormats/EcalObjects/interface/EcalEBPhase2TPGPedestals.h @@ -0,0 +1,20 @@ +#ifndef CondFormats_EcalObjects_EcalEBPhase2TPGPedestals_h +#define CondFormats_EcalObjects_EcalEBPhase2TPGPedestals_h + +#include "CondFormats/Serialization/interface/Serializable.h" + +#include "CondFormats/EcalObjects/interface/EcalCondObjectContainer.h" + +struct EcalEBPhase2TPGPedestal { + EcalEBPhase2TPGPedestal() : mean_x10(0), mean_x1(0) {} + uint32_t mean_x10; + uint32_t mean_x1; + + COND_SERIALIZABLE; +}; + +typedef EcalCondObjectContainer EcalEBPhase2TPGPedestalsMap; +typedef EcalEBPhase2TPGPedestalsMap::const_iterator EcalEBPhase2TPGPedestalsMapIterator; +typedef EcalEBPhase2TPGPedestalsMap EcalEBPhase2TPGPedestals; + +#endif diff --git a/CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeightIdMap.h b/CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeightIdMap.h new file mode 100644 index 0000000000000..051b7c0988227 --- /dev/null +++ b/CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeightIdMap.h @@ -0,0 +1,27 @@ +#ifndef CondFormats_EcalObjects_EcalEBPhase2TPGTimeWeightIdMap_h +#define CondFormats_EcalObjects_EcalEBPhase2TPGTimeWeightIdMap_h + +#include "CondFormats/Serialization/interface/Serializable.h" + +#include +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeights.h" +#include + +class EcalEBPhase2TPGTimeWeightIdMap { +public: + typedef std::map EcalEBPhase2TPGTimeWeightMap; + typedef std::map::const_iterator EcalEBPhase2TPGTimeWeightMapItr; + + EcalEBPhase2TPGTimeWeightIdMap() {} + ~EcalEBPhase2TPGTimeWeightIdMap() {} + + const EcalEBPhase2TPGTimeWeightMap& getMap() const { return map_; } + void setValue(const uint32_t& id, const EcalEBPhase2TPGTimeWeights& value); + +private: + EcalEBPhase2TPGTimeWeightMap map_; + + COND_SERIALIZABLE; +}; + +#endif diff --git a/CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeights.h b/CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeights.h new file mode 100644 index 0000000000000..b534733d5af87 --- /dev/null +++ b/CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeights.h @@ -0,0 +1,56 @@ +#ifndef CondFormats_EcalObjects_EcalEBPhase2TPGTimelWeights_h +#define CondFormats_EcalObjects_EcalEBPhase2TPGTimelWeights_h + +#include "CondFormats/Serialization/interface/Serializable.h" + +#include +#include + +class EcalEBPhase2TPGTimeWeights { +public: + EcalEBPhase2TPGTimeWeights(); + ~EcalEBPhase2TPGTimeWeights() {} + + void getValues(uint32_t& w0, + uint32_t& w1, + uint32_t& w2, + uint32_t& w3, + uint32_t& w4, + uint32_t& w5, + uint32_t& w6, + uint32_t& w7, + uint32_t& w8, + uint32_t& w9, + uint32_t& w10, + uint32_t& w11) const; + void setValues(const uint32_t& w0, + const uint32_t& w1, + const uint32_t& w2, + const uint32_t& w3, + const uint32_t& w4, + const uint32_t& w5, + const uint32_t& w6, + const uint32_t& w7, + const uint32_t& w8, + const uint32_t& w9, + const uint32_t& w10, + const uint32_t& w11); + +private: + uint32_t w0_; + uint32_t w1_; + uint32_t w2_; + uint32_t w3_; + uint32_t w4_; + uint32_t w5_; + uint32_t w6_; + uint32_t w7_; + uint32_t w8_; + uint32_t w9_; + uint32_t w10_; + uint32_t w11_; + + COND_SERIALIZABLE; +}; + +#endif diff --git a/CondFormats/EcalObjects/src/EcalEBPhase2TPGAmplWeightIdMap.cc b/CondFormats/EcalObjects/src/EcalEBPhase2TPGAmplWeightIdMap.cc new file mode 100644 index 0000000000000..8f7f1d3aa59ed --- /dev/null +++ b/CondFormats/EcalObjects/src/EcalEBPhase2TPGAmplWeightIdMap.cc @@ -0,0 +1,5 @@ +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeightIdMap.h" + +void EcalEBPhase2TPGAmplWeightIdMap::setValue(const uint32_t& id, const EcalEBPhase2TPGAmplWeights& value) { + map_[id] = value; +} diff --git a/CondFormats/EcalObjects/src/EcalEBPhase2TPGAmplWeights.cc b/CondFormats/EcalObjects/src/EcalEBPhase2TPGAmplWeights.cc new file mode 100644 index 0000000000000..dafbd250ee753 --- /dev/null +++ b/CondFormats/EcalObjects/src/EcalEBPhase2TPGAmplWeights.cc @@ -0,0 +1,58 @@ +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeights.h" + +EcalEBPhase2TPGAmplWeights::EcalEBPhase2TPGAmplWeights() + : w0_(0), w1_(0), w2_(0), w3_(0), w4_(0), w5_(0), w6_(0), w7_(0), w8_(0), w9_(0), w10_(0), w11_(0) {} + +EcalEBPhase2TPGAmplWeights::~EcalEBPhase2TPGAmplWeights() {} + +void EcalEBPhase2TPGAmplWeights::getValues(uint32_t& w0, + uint32_t& w1, + uint32_t& w2, + uint32_t& w3, + uint32_t& w4, + uint32_t& w5, + uint32_t& w6, + uint32_t& w7, + uint32_t& w8, + uint32_t& w9, + uint32_t& w10, + uint32_t& w11) const { + w0 = w0_; + w1 = w1_; + w2 = w2_; + w3 = w3_; + w4 = w4_; + w5 = w5_; + w6 = w6_; + w7 = w7_; + w8 = w8_; + w9 = w9_; + w10 = w10_; + w11 = w11_; +} + +void EcalEBPhase2TPGAmplWeights::setValues(const uint32_t& w0, + const uint32_t& w1, + const uint32_t& w2, + const uint32_t& w3, + const uint32_t& w4, + const uint32_t& w5, + const uint32_t& w6, + const uint32_t& w7, + const uint32_t& w8, + const uint32_t& w9, + const uint32_t& w10, + const uint32_t& w11) { + w0_ = w0; + w1_ = w1; + w2_ = w2; + w3_ = w3; + w4_ = w4; + w5_ = w5; + w6_ = w6; + w7_ = w7; + w8_ = w8; + w9_ = w9; + w10_ = w10; + w11_ = w11; +} diff --git a/CondFormats/EcalObjects/src/EcalEBPhase2TPGTimeWeightIdMap.cc b/CondFormats/EcalObjects/src/EcalEBPhase2TPGTimeWeightIdMap.cc new file mode 100644 index 0000000000000..dc2124524e175 --- /dev/null +++ b/CondFormats/EcalObjects/src/EcalEBPhase2TPGTimeWeightIdMap.cc @@ -0,0 +1,5 @@ +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeightIdMap.h" + +void EcalEBPhase2TPGTimeWeightIdMap::setValue(const uint32_t& id, const EcalEBPhase2TPGTimeWeights& value) { + map_[id] = value; +} diff --git a/CondFormats/EcalObjects/src/EcalEBPhase2TPGTimeWeights.cc b/CondFormats/EcalObjects/src/EcalEBPhase2TPGTimeWeights.cc new file mode 100644 index 0000000000000..bbc5d47e3973f --- /dev/null +++ b/CondFormats/EcalObjects/src/EcalEBPhase2TPGTimeWeights.cc @@ -0,0 +1,56 @@ +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeights.h" + +EcalEBPhase2TPGTimeWeights::EcalEBPhase2TPGTimeWeights() + : w0_(0), w1_(0), w2_(0), w3_(0), w4_(0), w5_(0), w6_(0), w7_(0), w8_(0), w9_(0), w10_(0), w11_(0) {} + +void EcalEBPhase2TPGTimeWeights::getValues(uint32_t& w0, + uint32_t& w1, + uint32_t& w2, + uint32_t& w3, + uint32_t& w4, + uint32_t& w5, + uint32_t& w6, + uint32_t& w7, + uint32_t& w8, + uint32_t& w9, + uint32_t& w10, + uint32_t& w11) const { + w0 = w0_; + w1 = w1_; + w2 = w2_; + w3 = w3_; + w4 = w4_; + w5 = w5_; + w6 = w6_; + w7 = w7_; + w8 = w8_; + w9 = w9_; + w10 = w10_; + w11 = w11_; +} + +void EcalEBPhase2TPGTimeWeights::setValues(const uint32_t& w0, + const uint32_t& w1, + const uint32_t& w2, + const uint32_t& w3, + const uint32_t& w4, + const uint32_t& w5, + const uint32_t& w6, + const uint32_t& w7, + const uint32_t& w8, + const uint32_t& w9, + const uint32_t& w10, + const uint32_t& w11) { + w0_ = w0; + w1_ = w1; + w2_ = w2; + w3_ = w3; + w4_ = w4; + w5_ = w5; + w6_ = w6; + w7_ = w7; + w8_ = w8; + w9_ = w9; + w10_ = w10; + w11_ = w11; +} diff --git a/CondFormats/EcalObjects/src/T_EventSetup_EcalEBPhase2TPGAmplWeightIdMap.cc b/CondFormats/EcalObjects/src/T_EventSetup_EcalEBPhase2TPGAmplWeightIdMap.cc new file mode 100644 index 0000000000000..60f388c8131b7 --- /dev/null +++ b/CondFormats/EcalObjects/src/T_EventSetup_EcalEBPhase2TPGAmplWeightIdMap.cc @@ -0,0 +1,14 @@ +// -*- C++ -*- +// +// Author: Nancy Marinelli +// Created: +// $Id: T_EventSetup_EcalEBPhase2TPGAmplWeightIdMap.cc $ +// + +// system include files + +// user include files +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeightIdMap.h" +#include "FWCore/Utilities/interface/typelookup.h" + +TYPELOOKUP_DATA_REG(EcalEBPhase2TPGAmplWeightIdMap); diff --git a/CondFormats/EcalObjects/src/T_EventSetup_EcalEBPhase2TPGLinearizationConst.cc b/CondFormats/EcalObjects/src/T_EventSetup_EcalEBPhase2TPGLinearizationConst.cc new file mode 100644 index 0000000000000..a5568f53950be --- /dev/null +++ b/CondFormats/EcalObjects/src/T_EventSetup_EcalEBPhase2TPGLinearizationConst.cc @@ -0,0 +1,17 @@ +// -*- C++ -*- +// +// Implementation: +// create all the 'infrastructure' needed to get into the Context +// +// Author: Nancy Marinelli +// Created: +// $Id: T_EventSetup_EcalEBPhase2TPGLinearizationConst.cc $ +// + +// system include files + +// user include files +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGLinearizationConst.h" +#include "FWCore/Utilities/interface/typelookup.h" + +TYPELOOKUP_DATA_REG(EcalEBPhase2TPGLinearizationConst); diff --git a/CondFormats/EcalObjects/src/T_EventSetup_EcalEBPhase2TPGPedestals.cc b/CondFormats/EcalObjects/src/T_EventSetup_EcalEBPhase2TPGPedestals.cc new file mode 100644 index 0000000000000..6919fbd5dd486 --- /dev/null +++ b/CondFormats/EcalObjects/src/T_EventSetup_EcalEBPhase2TPGPedestals.cc @@ -0,0 +1,17 @@ +// -*- C++ -*- +// +// Implementation: +// create all the 'infrastructure' needed to get into the Context +// +// Author: Nancy Marinelli +// Created: +// $Id: T_EventSetup_EcalEBPhase2TPGPedestals.cc $ +// + +// system include files + +// user include files +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGPedestals.h" +#include "FWCore/Utilities/interface/typelookup.h" + +TYPELOOKUP_DATA_REG(EcalEBPhase2TPGPedestals); diff --git a/CondFormats/EcalObjects/src/T_EventSetup_EcalEBPhase2TPGTimeWeightIdMap.cc b/CondFormats/EcalObjects/src/T_EventSetup_EcalEBPhase2TPGTimeWeightIdMap.cc new file mode 100644 index 0000000000000..2b326b3ad9f3a --- /dev/null +++ b/CondFormats/EcalObjects/src/T_EventSetup_EcalEBPhase2TPGTimeWeightIdMap.cc @@ -0,0 +1,13 @@ +// -*- C++ -*- +// +// Author: Nancy Marinelli +// $Id: T_EventSetup_EcalEBPhase2TPGTimeWeightIdMap.cc $ +// + +// system include files + +// user include files +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeightIdMap.h" +#include "FWCore/Utilities/interface/typelookup.h" + +TYPELOOKUP_DATA_REG(EcalEBPhase2TPGTimeWeightIdMap); diff --git a/CondFormats/EcalObjects/src/classes.h b/CondFormats/EcalObjects/src/classes.h index cf9e4896a0f2b..ed447d09237a9 100644 --- a/CondFormats/EcalObjects/src/classes.h +++ b/CondFormats/EcalObjects/src/classes.h @@ -73,3 +73,7 @@ //ECAL PH2: #include "CondFormats/EcalObjects/interface/EcalLiteDTUPedestals.h" #include "CondFormats/EcalObjects/interface/EcalCATIAGainRatios.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeightIdMap.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeightIdMap.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGLinearizationConst.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGPedestals.h" diff --git a/CondFormats/EcalObjects/src/classes_def.xml b/CondFormats/EcalObjects/src/classes_def.xml index a6895cbdf9f58..76e5ece0cb2fe 100644 --- a/CondFormats/EcalObjects/src/classes_def.xml +++ b/CondFormats/EcalObjects/src/classes_def.xml @@ -112,6 +112,18 @@ + + + + + + + + + + + + @@ -123,6 +135,19 @@ + + + + + + + + + + + + + @@ -224,6 +249,12 @@ + + + + + + diff --git a/Configuration/Eras/python/Modifier_phase2_ecalTP_devel_cff.py b/Configuration/Eras/python/Modifier_phase2_ecalTP_devel_cff.py new file mode 100644 index 0000000000000..cd60a1aa06ca6 --- /dev/null +++ b/Configuration/Eras/python/Modifier_phase2_ecalTP_devel_cff.py @@ -0,0 +1,4 @@ +import FWCore.ParameterSet.Config as cms + +phase2_ecalTP_devel = cms.Modifier() + diff --git a/Configuration/StandardSequences/python/Eras.py b/Configuration/StandardSequences/python/Eras.py index de49f65893322..76c788dcf3e7d 100644 --- a/Configuration/StandardSequences/python/Eras.py +++ b/Configuration/StandardSequences/python/Eras.py @@ -70,7 +70,7 @@ def __init__(self): 'phase2_common', 'phase2_tracker', 'phase2_muon', 'phase2_GEM', 'phase2_GE0', 'phase2_hgcal', 'phase2_timing', 'phase2_hfnose', 'phase2_hgcalV10', 'phase2_hgcalV11', 'phase2_hgcalV12', - 'phase2_timing_layer', 'phase2_etlV4', 'phase2_hcal', 'phase2_ecal','phase2_ecal_devel', + 'phase2_timing_layer', 'phase2_etlV4', 'phase2_hcal', 'phase2_ecal','phase2_ecal_devel', 'phase2_ecalTP_devel', 'phase2_trigger', 'phase2_squarePixels', 'phase2_3DPixels', 'trackingLowPU', 'trackingPhase1', diff --git a/DataFormats/EcalDigi/interface/EBDataFrame_Ph2.h b/DataFormats/EcalDigi/interface/EBDataFrame_Ph2.h new file mode 100644 index 0000000000000..aaaf3f8f8ef1b --- /dev/null +++ b/DataFormats/EcalDigi/interface/EBDataFrame_Ph2.h @@ -0,0 +1,28 @@ +#ifndef DataFormats_EcalDigi_EBDataFrame_Ph2_h +#define DataFormats_EcalDigi_EBDataFrame_Ph2_h + +#include "DataFormats/EcalDetId/interface/EBDetId.h" +#include "DataFormats/EcalDigi/interface/EcalDataFrame_Ph2.h" +#include + +/** \class EBDataFrame + +*/ +class EBDataFrame_Ph2 : public EcalDataFrame_Ph2 { +public: + typedef EBDetId key_type; + typedef EcalDataFrame_Ph2 Base; + + EBDataFrame_Ph2() {} + + EBDataFrame_Ph2(edm::DataFrame const& base) : Base(base) {} + EBDataFrame_Ph2(EcalDataFrame_Ph2 const& base) : Base(base) {} + + ~EBDataFrame_Ph2() override {} + + key_type id() const { return Base::id(); } +}; + +std::ostream& operator<<(std::ostream&, const EBDataFrame_Ph2&); + +#endif diff --git a/DataFormats/EcalDigi/interface/EcalDigiCollections.h b/DataFormats/EcalDigi/interface/EcalDigiCollections.h index f9a79f9830972..6e4a04066a1f3 100644 --- a/DataFormats/EcalDigi/interface/EcalDigiCollections.h +++ b/DataFormats/EcalDigi/interface/EcalDigiCollections.h @@ -2,12 +2,14 @@ #define DIGIECAL_ECALDIGICOLLECTION_H #include "DataFormats/EcalDigi/interface/EBDataFrame.h" +#include "DataFormats/EcalDigi/interface/EBDataFrame_Ph2.h" #include "DataFormats/EcalDigi/interface/EcalDataFrame_Ph2.h" #include "DataFormats/EcalDigi/interface/EEDataFrame.h" #include "DataFormats/EcalDigi/interface/ESDataFrame.h" #include "DataFormats/EcalDigi/interface/EcalTimeDigi.h" #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h" #include "DataFormats/EcalDigi/interface/EcalEBTriggerPrimitiveDigi.h" +#include "DataFormats/EcalDigi/interface/EcalEBPhase2TriggerPrimitiveDigi.h" #include "DataFormats/EcalDigi/interface/EcalTrigPrimCompactColl.h" #include "DataFormats/EcalDigi/interface/EcalPseudoStripInputDigi.h" #include "DataFormats/EcalDigi/interface/EBSrFlag.h" @@ -120,6 +122,7 @@ inline void swap(EBDigiCollectionPh2& lhs, EBDigiCollectionPh2& rhs) { lhs.swap( typedef edm::SortedCollection EcalTimeDigiCollection; typedef edm::SortedCollection EcalTrigPrimDigiCollection; typedef edm::SortedCollection EcalEBTrigPrimDigiCollection; +typedef edm::SortedCollection EcalEBPhase2TrigPrimDigiCollection; typedef edm::SortedCollection EcalPSInputDigiCollection; typedef edm::SortedCollection EBSrFlagCollection; diff --git a/DataFormats/EcalDigi/interface/EcalEBPhase2TriggerPrimitiveDigi.h b/DataFormats/EcalDigi/interface/EcalEBPhase2TriggerPrimitiveDigi.h new file mode 100644 index 0000000000000..82293612f16d7 --- /dev/null +++ b/DataFormats/EcalDigi/interface/EcalEBPhase2TriggerPrimitiveDigi.h @@ -0,0 +1,63 @@ +#ifndef DataFormats_EcalDigi_EcalEBPhase2TriggerPrimitiveDigi_h +#define DataFormats_EcalDigi_EcalEBPhase2TriggerPrimitiveDigi_h + +#include +#include +#include "DataFormats/EcalDetId/interface/EBDetId.h" +#include "DataFormats/EcalDigi/interface/EcalEBPhase2TriggerPrimitiveSample.h" + +/** \class EcalEBPhase2TriggerPrimitiveDigi +\author N. Marinelli - Univ. of Notre Dame + + +*/ + +class EcalEBPhase2TriggerPrimitiveDigi { +public: + typedef EBDetId key_type; ///< For the sorted collection + + EcalEBPhase2TriggerPrimitiveDigi(); // for persistence + EcalEBPhase2TriggerPrimitiveDigi(const EBDetId& id); + + void swap(EcalEBPhase2TriggerPrimitiveDigi& rh) { + std::swap(id_, rh.id_); + std::swap(size_, rh.size_); + std::swap(data_, rh.data_); + } + + const EBDetId& id() const { return id_; } + int size() const { return size_; } + + const EcalEBPhase2TriggerPrimitiveSample& operator[](int i) const { return data_[i]; } + const EcalEBPhase2TriggerPrimitiveSample& sample(int i) const { return data_[i]; } + + void setSize(int size); + void setSample(int i, const EcalEBPhase2TriggerPrimitiveSample& sam); + void setSampleValue(int i, uint16_t value) { data_[i].setValue(value); } + + /// get the 12 bits Et of interesting sample + int encodedEt() const; + + /// Spike flag + bool l1aSpike() const; + + /// Time info + int time() const; + + /// True if debug mode (# of samples > 1) + bool isDebug() const; + + /// Gets the interesting sample + int sampleOfInterest() const; + +private: + EBDetId id_; + int size_; + std::vector data_; +}; + +inline void swap(EcalEBPhase2TriggerPrimitiveDigi& lh, EcalEBPhase2TriggerPrimitiveDigi& rh) { lh.swap(rh); } + +std::ostream& operator<<(std::ostream& s, const EcalEBPhase2TriggerPrimitiveDigi& digi); + +#endif diff --git a/DataFormats/EcalDigi/interface/EcalEBPhase2TriggerPrimitiveSample.h b/DataFormats/EcalDigi/interface/EcalEBPhase2TriggerPrimitiveSample.h new file mode 100644 index 0000000000000..3cc7806b1b275 --- /dev/null +++ b/DataFormats/EcalDigi/interface/EcalEBPhase2TriggerPrimitiveSample.h @@ -0,0 +1,49 @@ +#ifndef DataFormats_EcalDig_EcalEBPhase2TriggerPrimitiveSample_h +#define DataFormats_EcalDig_EcalEBPhase2TriggerPrimitiveSample_h + +#include +#include + +/** \class EcalEBPhase2TriggerPrimitiveSample +\author N. Marinelli - Univ of Notre Dame + +*/ + +class EcalEBPhase2TriggerPrimitiveSample { +public: + EcalEBPhase2TriggerPrimitiveSample(); + EcalEBPhase2TriggerPrimitiveSample(uint32_t data); + EcalEBPhase2TriggerPrimitiveSample(int encodedEt); + EcalEBPhase2TriggerPrimitiveSample(int encodedEt, bool isASpike); + EcalEBPhase2TriggerPrimitiveSample(int encodedEt, bool isASpike, int timing); + + ///Set data + void setValue(uint32_t data) { theSample_ = data; } + // The sample is a 18 bit word defined as: + // + // o o o o o o o o o o o o o o o o o o + // |________| |_______________________| + // ~60ps res spike Et + // time info flag + // + + /// get the raw word + uint32_t raw() const { return theSample_ & 0x3ffff; } + + /// get the encoded Et (12 bits) + int encodedEt() const { return (theSample_ & 0x3ffff) & 0xFFF; } + + bool l1aSpike() const { return (theSample_ & 0x3ffff & 0x1000) != 0; } + + int time() const { return (theSample_ & 0x3ffff) >> 13; } + + /// for streaming + uint32_t operator()() { return theSample_ & 0x3ffff; } + +private: + uint32_t theSample_; +}; + +std::ostream& operator<<(std::ostream& s, const EcalEBPhase2TriggerPrimitiveSample& samp); + +#endif diff --git a/DataFormats/EcalDigi/interface/EcalEBTriggerPrimitiveSample.h b/DataFormats/EcalDigi/interface/EcalEBTriggerPrimitiveSample.h index 105eac61088db..271f76c329d9d 100644 --- a/DataFormats/EcalDigi/interface/EcalEBTriggerPrimitiveSample.h +++ b/DataFormats/EcalDigi/interface/EcalEBTriggerPrimitiveSample.h @@ -21,8 +21,8 @@ class EcalEBTriggerPrimitiveSample { void setValue(uint16_t data) { theSample = data; } // The sample is a 16 bit word defined as: // - // o o o o o o o o o o o o o o o o - // |________| |____________________| + // o o o o o o o o o o o o o o o o + // |________| |_______________________| // ~60ps res spike Et // time info flag // @@ -31,7 +31,7 @@ class EcalEBTriggerPrimitiveSample { uint16_t raw() const { return theSample; } /// get the encoded Et (10 bits) - int encodedEt() const { return theSample & 0x3FF; } + int encodedEt() const { return theSample & 0x3ff; } bool l1aSpike() const { return (theSample & 0x400) != 0; } diff --git a/DataFormats/EcalDigi/src/EBDataFrame_Ph2.cc b/DataFormats/EcalDigi/src/EBDataFrame_Ph2.cc new file mode 100644 index 0000000000000..f48a09cf0eb88 --- /dev/null +++ b/DataFormats/EcalDigi/src/EBDataFrame_Ph2.cc @@ -0,0 +1,10 @@ +#include "DataFormats/EcalDigi/interface/EBDataFrame_Ph2.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include + +std::ostream& operator<<(std::ostream& s, const EBDataFrame_Ph2& digi) { + s << digi.id() << " " << digi.size() << " samples " << std::endl; + for (int i = 0; i < digi.size(); i++) + s << " " << digi[i] << std::endl; + return s; +} diff --git a/DataFormats/EcalDigi/src/EcalEBPhase2TriggerPrimitiveDigi.cc b/DataFormats/EcalDigi/src/EcalEBPhase2TriggerPrimitiveDigi.cc new file mode 100644 index 0000000000000..08be20ff807e3 --- /dev/null +++ b/DataFormats/EcalDigi/src/EcalEBPhase2TriggerPrimitiveDigi.cc @@ -0,0 +1,61 @@ +#include "DataFormats/EcalDigi/interface/EcalEBPhase2TriggerPrimitiveDigi.h" +#include +#include + +static constexpr int MAXSAMPLES = 20; +// This is the number of digi samples one wants to put in the TP digis. In Phase I was 5, but this setting was used. In the end in Phase I one one sample, corresponding to BC0 was filled. For Phase2 we have not decided yet. We leave this setting as it is while we decide what to do + +EcalEBPhase2TriggerPrimitiveDigi::EcalEBPhase2TriggerPrimitiveDigi() : size_(0), data_(MAXSAMPLES) {} + +EcalEBPhase2TriggerPrimitiveDigi::EcalEBPhase2TriggerPrimitiveDigi(const EBDetId& id) + : id_(id), size_(0), data_(MAXSAMPLES) {} + +void EcalEBPhase2TriggerPrimitiveDigi::setSample(int i, const EcalEBPhase2TriggerPrimitiveSample& sam) { + data_[i] = sam; +} + +int EcalEBPhase2TriggerPrimitiveDigi::sampleOfInterest() const { + // sample of interest to be save in the TP digis + if (size_ == 1) + return 0; + else if (size_ == 5) + return 2; + else + return -1; +} + +/// get the encoded/compressed Et of interesting sample +int EcalEBPhase2TriggerPrimitiveDigi::encodedEt() const { + int sample = sampleOfInterest(); + if (sample != -1) + return data_[sample].encodedEt(); + else + return -1; +} + +bool EcalEBPhase2TriggerPrimitiveDigi::l1aSpike() const { + int sample = sampleOfInterest(); + if (sample != -1) + return data_[sample].l1aSpike(); + else + return -1; +} + +int EcalEBPhase2TriggerPrimitiveDigi::time() const { + int sample = sampleOfInterest(); + if (sample != -1) + return data_[sample].time(); + else + return -1; +} + +bool EcalEBPhase2TriggerPrimitiveDigi::isDebug() const { return (size_ > 1); } + +void EcalEBPhase2TriggerPrimitiveDigi::setSize(int size) { size_ = std::clamp(size_, 0, MAXSAMPLES); } + +std::ostream& operator<<(std::ostream& s, const EcalEBPhase2TriggerPrimitiveDigi& digi) { + s << digi.id() << " " << digi.size() << " samples " << std::endl; + for (int i = 0; i < digi.size(); i++) + s << " " << digi.sample(i) << std::endl; + return s; +} diff --git a/DataFormats/EcalDigi/src/EcalEBPhase2TriggerPrimitiveSample.cc b/DataFormats/EcalDigi/src/EcalEBPhase2TriggerPrimitiveSample.cc new file mode 100644 index 0000000000000..c52762709801b --- /dev/null +++ b/DataFormats/EcalDigi/src/EcalEBPhase2TriggerPrimitiveSample.cc @@ -0,0 +1,26 @@ +#include "DataFormats/EcalDigi/interface/EcalEBPhase2TriggerPrimitiveSample.h" +#include + +EcalEBPhase2TriggerPrimitiveSample::EcalEBPhase2TriggerPrimitiveSample() : theSample_(0) {} +EcalEBPhase2TriggerPrimitiveSample::EcalEBPhase2TriggerPrimitiveSample(uint32_t data) : theSample_(data) { + theSample_ = theSample_ & 0x3ffff; +} + +EcalEBPhase2TriggerPrimitiveSample::EcalEBPhase2TriggerPrimitiveSample(int encodedEt, bool isASpike) { + theSample_ = (encodedEt & 0xFFF) | ((isASpike) ? (0x1000) : (0)); + theSample_ = theSample_ & 0x3ffff; +} + +EcalEBPhase2TriggerPrimitiveSample::EcalEBPhase2TriggerPrimitiveSample(int encodedEt, bool isASpike, int timing) { + theSample_ = (encodedEt & 0xFFF) | ((isASpike) ? (0x1000) : (0)) | timing << 13; + theSample_ = theSample_ & 0x3ffff; +} + +EcalEBPhase2TriggerPrimitiveSample::EcalEBPhase2TriggerPrimitiveSample(int encodedEt) { + theSample_ = encodedEt & 0xFFF; + theSample_ = theSample_ & 0x3ffff; +} + +std::ostream& operator<<(std::ostream& s, const EcalEBPhase2TriggerPrimitiveSample& samp) { + return s << "ET=" << samp.encodedEt() << ", isASpike=" << samp.l1aSpike() << " timing= " << samp.time(); +} diff --git a/DataFormats/EcalDigi/src/EcalEBTriggerPrimitiveSample.cc b/DataFormats/EcalDigi/src/EcalEBTriggerPrimitiveSample.cc index 2ff8b7b7f271c..d5b6b4010a91c 100644 --- a/DataFormats/EcalDigi/src/EcalEBTriggerPrimitiveSample.cc +++ b/DataFormats/EcalDigi/src/EcalEBTriggerPrimitiveSample.cc @@ -1,4 +1,5 @@ #include "DataFormats/EcalDigi/interface/EcalEBTriggerPrimitiveSample.h" +#include EcalEBTriggerPrimitiveSample::EcalEBTriggerPrimitiveSample() : theSample(0) {} EcalEBTriggerPrimitiveSample::EcalEBTriggerPrimitiveSample(uint16_t data) : theSample(data) {} diff --git a/DataFormats/EcalDigi/src/classes_def.xml b/DataFormats/EcalDigi/src/classes_def.xml index 7893cc71b2bf2..ec5091b2f078d 100644 --- a/DataFormats/EcalDigi/src/classes_def.xml +++ b/DataFormats/EcalDigi/src/classes_def.xml @@ -11,6 +11,9 @@ + + + @@ -20,12 +23,18 @@ + + + + + + @@ -69,6 +78,7 @@ + @@ -114,6 +124,8 @@ + + @@ -126,6 +138,7 @@ + diff --git a/SimCalorimetry/Configuration/python/SimCalorimetry_EventContent_cff.py b/SimCalorimetry/Configuration/python/SimCalorimetry_EventContent_cff.py index 722afe99fc13e..b5ca031128fbf 100644 --- a/SimCalorimetry/Configuration/python/SimCalorimetry_EventContent_cff.py +++ b/SimCalorimetry/Configuration/python/SimCalorimetry_EventContent_cff.py @@ -7,6 +7,7 @@ 'keep *_simEcalPreshowerDigis_*_*', 'keep *_simEcalTriggerPrimitiveDigis_*_*', 'keep *_simEcalEBTriggerPrimitiveDigis_*_*', + 'keep *_simEcalEBTriggerPrimitivePhase2Digis_*_*', 'keep *_simHcalDigis_*_*', 'keep ZDCDataFramesSorted_simHcalUnsuppressedDigis_*_*', 'drop ZDCDataFramesSorted_mix_simHcalUnsuppressedDigis*_*', diff --git a/SimCalorimetry/Configuration/python/ecalDigiSequence_cff.py b/SimCalorimetry/Configuration/python/ecalDigiSequence_cff.py index 50275b8cbbb70..947fe094fbf11 100644 --- a/SimCalorimetry/Configuration/python/ecalDigiSequence_cff.py +++ b/SimCalorimetry/Configuration/python/ecalDigiSequence_cff.py @@ -21,6 +21,8 @@ _phase2_ecalDigiTask = ecalDigiTask.copy() _phase2_ecalDigiTask.add(simEcalEBTriggerPrimitiveDigis) + + from Configuration.Eras.Modifier_phase2_common_cff import phase2_common phase2_common.toReplaceWith(ecalDigiTask,_phase2_ecalDigiTask) @@ -28,9 +30,19 @@ _phase2_ecalDigiTask_devel = cms.Task() phase2_ecal_devel.toReplaceWith(ecalDigiTask,_phase2_ecalDigiTask_devel) -#phase 2 ecal + +from Configuration.Eras.Modifier_phase2_ecalTP_devel_cff import phase2_ecalTP_devel +from SimCalorimetry.EcalEBTrigPrimProducers.ecalEBTriggerPrimitivePhase2Digis_cfi import * +_phase2_ecalDigiTask_devel2 = cms.Task(simEcalEBTriggerPrimitivePhase2Digis) +phase2_ecalTP_devel.toReplaceWith(ecalDigiTask,_phase2_ecalDigiTask_devel2) + +#phase 2 ecal def _modifyEcalForPh2( process ): process.load("SimCalorimetry.EcalSimProducers.esEcalLiteDTUPedestalsProducer_cfi") process.load("SimCalorimetry.EcalSimProducers.esCATIAGainProducer_cfi") - modifyDigi_Phase2EcalPed = phase2_ecal_devel.makeProcessModifier(_modifyEcalForPh2) + + +def _modifyEcalTPForPh2( process ): + process.load("SimCalorimetry.EcalEBTrigPrimProducers.ecalEBTriggerPrimitivePhase2ESProducer_cfi") +modifyDigi_Phase2EcalTP = phase2_ecalTP_devel.makeProcessModifier(_modifyEcalTPForPh2) diff --git a/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2AmplitudeReconstructor.h b/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2AmplitudeReconstructor.h new file mode 100644 index 0000000000000..a7098e6c62c76 --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2AmplitudeReconstructor.h @@ -0,0 +1,38 @@ +#ifndef SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBPhase2AmplitudeReconstructor_h +#define SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBPhase2AmplitudeReconstructor_h + +#include +#include + +class EcalEBPhase2TPGAmplWeightIdMap; +class EcalTPGWeightGroup; + +/** \class EcalPhase2AmplitudeReconstructor +\author L. Lutton, N. Marinelli - Univ. of Notre Dame + Description: forPhase II + It uses the new Phase2 digis based on the new EB electronics + and measures the amplitude on xTals basis +*/ + +class EcalEBPhase2AmplitudeReconstructor { +private: + static const int maxSamplesUsed_ = 12; + bool debug_; + int inputsAlreadyIn_; + int buffer_[maxSamplesUsed_]; + int weights_[maxSamplesUsed_]; + int shift_; + int setInput(int input); + void process(); + int processedOutput_; + +public: + EcalEBPhase2AmplitudeReconstructor(bool debug); + virtual ~EcalEBPhase2AmplitudeReconstructor(); + virtual void process(std::vector &addout, std::vector &output); + void setParameters(uint32_t raw, + const EcalEBPhase2TPGAmplWeightIdMap *ecaltpgWeightMap, + const EcalTPGWeightGroup *ecaltpgWeightGroup); +}; + +#endif diff --git a/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2Linearizer.h b/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2Linearizer.h new file mode 100644 index 0000000000000..6b86db0dcfb5b --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2Linearizer.h @@ -0,0 +1,58 @@ +#ifndef SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBPhase2Linearizer_h +#define SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBPhase2Linearizer_h + +#include "DataFormats/EcalDigi/interface/EcalLiteDTUSample.h" +#include "DataFormats/EcalDigi/interface/EcalDigiCollections.h" +#include "CondFormats/EcalObjects/interface/EcalLiteDTUPedestals.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGLinearizationConst.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGPedestals.h" + +#include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h" + +#include + +/** \class EcalEBPhase2Linearizer +\author L. Lutton, N. Marinelli - Univ. of Notre Dame + Description: forPhase II + Performs the linearization of signal from Catia+LiteDTU +*/ + +class EcalEBPhase2Linearizer { +private: + bool debug_; + int uncorrectedSample_; + int gainID_; + uint base_; + uint mult_; + uint shift_; + int strip_; + bool init_; + float gainDivideByTen_ = 0.1; + std::vector coeffs_; + uint coeff_; + //I2C Stuff. Would eventually get from outside linearizer (e.g., database) + //Would also be different for each crystal + uint I2CSub_; + + const EcalLiteDTUPedestals *peds_; + const EcalEBPhase2TPGLinearizationConstant *linConsts_; + const EcalTPGCrystalStatusCode *badXStatus_; + + std::vector vectorbadXStatus_; + + int setInput(const EcalLiteDTUSample &RawSam); + + int doOutput(); + +public: + EcalEBPhase2Linearizer(bool debug); + virtual ~EcalEBPhase2Linearizer(); + + void process(const EBDigiCollectionPh2::Digi &df, std::vector &output_percry); + void setParameters(EBDetId id, + const EcalLiteDTUPedestalsMap *peds, + const EcalEBPhase2TPGLinearizationConstMap *ecaltplin, + const EcalTPGCrystalStatus *ecaltpBadX); +}; + +#endif diff --git a/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2SpikeTagger.h b/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2SpikeTagger.h new file mode 100644 index 0000000000000..1df64a51eee46 --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2SpikeTagger.h @@ -0,0 +1,36 @@ +#ifndef SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBPhase2SpikeTagger_h +#define SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBPhase2SpikeTagger_h + +#include "DataFormats/EcalDigi/interface/EcalLiteDTUSample.h" +#include "DataFormats/EcalDigi/interface/EcalDigiCollections.h" +#include "CondFormats/EcalObjects/interface/EcalLiteDTUPedestals.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGLinearizationConst.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGPedestals.h" + +#include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h" + +#include + +/** \class EcalEBPhase2SpikeTagger + Tags spikes on a channel basis +*/ + +class EcalEBPhase2SpikeTagger { +private: + bool debug_; + const EcalLiteDTUPedestals *peds_; + const EcalEBPhase2TPGLinearizationConstant *linConsts_; + const EcalTPGCrystalStatusCode *badXStatus_; + +public: + EcalEBPhase2SpikeTagger(bool debug); + virtual ~EcalEBPhase2SpikeTagger(); + + bool process(const std::vector &linInput); + void setParameters(EBDetId id, + const EcalLiteDTUPedestalsMap *peds, + const EcalEBPhase2TPGLinearizationConstMap *ecaltplin, + const EcalTPGCrystalStatus *ecaltpBadX); +}; + +#endif diff --git a/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TPFormatter.h b/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TPFormatter.h new file mode 100644 index 0000000000000..9a73aa394f491 --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TPFormatter.h @@ -0,0 +1,28 @@ +#ifndef SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBPhase2TPFormatter_h +#define SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBPhase2TPFormatter_h + +#include "DataFormats/EcalDigi/interface/EcalEBTriggerPrimitiveSample.h" + +#include +#include + +/* + \class EcalEBPhase2TPFormatter + +*/ + +class EcalEBPhase2TPFormatter { +private: + bool debug_; + std::vector inputAmp_; + std::vector inputTime_; + +public: + EcalEBPhase2TPFormatter(bool debug); + virtual ~EcalEBPhase2TPFormatter(); + virtual void process(std::vector& ampl, + std::vector& time, + std::vector& outampl, + std::vector& outtime); +}; +#endif diff --git a/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TimeReconstructor.h b/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TimeReconstructor.h new file mode 100644 index 0000000000000..0daa2a9676103 --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TimeReconstructor.h @@ -0,0 +1,115 @@ +#ifndef SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBPhase2TimeReconstructor_h +#define SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBPhase2TimeReconstructor_h + +#include +#include + +class EcalEBPhase2TPGTimeWeightIdMap; +class EcalTPGWeightGroup; + +/** \class EcalEBPhase2TimeReconstructor +\author L. Lutton, N. Marinelli - Univ. of Notre Dame + Description: forPhase II + Measures the timing of a xTal signal +*/ + +class EcalEBPhase2TimeReconstructor { +private: + static const int maxSamplesUsed_ = 12; + bool debug_; + int inputsAlreadyIn_; + int buffer_[maxSamplesUsed_]; + int weights_[maxSamplesUsed_]; + uint64_t ampIn_[maxSamplesUsed_]; + int shift_; + bool extraShift_[2] = {false, false}; + int setInput(int input); + void process(); + int processedOutput_; + + // The array invAmpPar is pre-calulated, at least for now since it has shown to be stable. We might decide at a later stage + // to make the calculation dynamic in CMSSW. + // Here some explnation of what this LUT is. + + //The sum of the digis multiplied by the time weight coefficients gives dT*A, where A is the amplitude. + //So to get dT the amplitude, calculated in EcalEBPhase2AmplitudeReconstructor, must be divided off of the result here. + //However, when this is implemented into the BCP hardware (of which we are emulating the behaviour), + //division is not a trivial operation, often requiring relatively large + //amounts of time and resources to complete. + //To optimize this operation, we instead use an approximation of that division via a lookup table (LUT). + //Think about the division as a multiplication of 1/A, then the LUT is filled with all the possible values of 1/A, + //precalculated, in the range that A takes and A itself is used to index the LUT. + //The element received is then multiplied by the dT*A result in order to get a measurement of the timing. + + //Another limitation of hardware is that we do not use floating point numbers. + //So, instead, each element of the LUT is bit shifted to the left by some amount sufficient to make every element + //of the LUT large enough such that converting it to an integer doesn't lead to a loss in performance + //(this bit shift is undone after the multiplication by a corresponding bit shift to the right). + //Another method of approximation used here is that not every element in A's range is included in the LUT. + //Instead, every 8th element is used, since the difference between, e.g., dividing by 1000 and 1008 is generally + //small whereas it can be a significant save in time and resources in hardware to use a smaller LUT. + //Note that this requires the indexing amplitude to be bit shifted by 3 to the right to compensate for the smaller size of the LUT. + //Finally, dT will be in units of ns, but to convert it to ps each element of the LUT is multiplied by 1000. + + //The pre-calculation of the LUT is given by: + //invAmpAr_ = [1000*invMult] #Since 1/0 is undefined, the array starts with 1/1. The rest of the elements will be filled in the following loop: + //for i in range(8,4096,8): #loop is set to do every 8th number, so 1/8, 1/16, 1/24, etc. 4096 is the expected range of A + //invAmpAr_.append(round((ns_to_ps_conv/i)*invMult)) + //Where ns_to_ps_conv = 1000 #this is to convert the resulting dT from units of ns to units of ps + //invMult = 2**18 #Acts as a shift by 18 bits that is done to the fractions to make them integers instead of floats. + + uint64_t invAmpAr_[512] = { + 262144000, 32768000, 16384000, 10922667, 8192000, 6553600, 5461333, 4681143, 4096000, 3640889, 3276800, 2978909, + 2730667, 2520615, 2340571, 2184533, 2048000, 1927529, 1820444, 1724632, 1638400, 1560381, 1489455, 1424696, + 1365333, 1310720, 1260308, 1213630, 1170286, 1129931, 1092267, 1057032, 1024000, 992970, 963765, 936229, + 910222, 885622, 862316, 840205, 819200, 799220, 780190, 762047, 744727, 728178, 712348, 697191, + 682667, 668735, 655360, 642510, 630154, 618264, 606815, 595782, 585143, 574877, 564966, 555390, + 546133, 537180, 528516, 520127, 512000, 504123, 496485, 489075, 481882, 474899, 468114, 461521, + 455111, 448877, 442811, 436907, 431158, 425558, 420103, 414785, 409600, 404543, 399610, 394795, + 390095, 385506, 381023, 376644, 372364, 368180, 364089, 360088, 356174, 352344, 348596, 344926, + 341333, 337814, 334367, 330990, 327680, 324436, 321255, 318136, 315077, 312076, 309132, 306243, + 303407, 300624, 297891, 295207, 292571, 289982, 287439, 284939, 282483, 280068, 277695, 275361, + 273067, 270810, 268590, 266407, 264258, 262144, 260063, 258016, 256000, 254016, 252062, 250137, + 248242, 246376, 244537, 242726, 240941, 239182, 237449, 235741, 234057, 232397, 230761, 229147, + 227556, 225986, 224438, 222912, 221405, 219919, 218453, 217007, 215579, 214170, 212779, 211406, + 210051, 208713, 207392, 206088, 204800, 203528, 202272, 201031, 199805, 198594, 197398, 196216, + 195048, 193893, 192753, 191626, 190512, 189410, 188322, 187246, 186182, 185130, 184090, 183061, + 182044, 181039, 180044, 179060, 178087, 177124, 176172, 175230, 174298, 173376, 172463, 171560, + 170667, 169782, 168907, 168041, 167184, 166335, 165495, 164663, 163840, 163025, 162218, 161419, + 160627, 159844, 159068, 158300, 157538, 156785, 156038, 155299, 154566, 153840, 153121, 152409, + 151704, 151005, 150312, 149626, 148945, 148271, 147604, 146942, 146286, 145636, 144991, 144352, + 143719, 143092, 142470, 141853, 141241, 140635, 140034, 139438, 138847, 138262, 137681, 137105, + 136533, 135967, 135405, 134848, 134295, 133747, 133203, 132664, 132129, 131598, 131072, 130550, + 130032, 129518, 129008, 128502, 128000, 127502, 127008, 126517, 126031, 125548, 125069, 124593, + 124121, 123653, 123188, 122727, 122269, 121814, 121363, 120915, 120471, 120029, 119591, 119156, + 118725, 118296, 117871, 117448, 117029, 116612, 116199, 115788, 115380, 114975, 114573, 114174, + 113778, 113384, 112993, 112605, 112219, 111836, 111456, 111078, 110703, 110330, 109960, 109592, + 109227, 108864, 108503, 108145, 107789, 107436, 107085, 106736, 106390, 106045, 105703, 105363, + 105026, 104690, 104357, 104025, 103696, 103369, 103044, 102721, 102400, 102081, 101764, 101449, + 101136, 100825, 100515, 100208, 99902, 99599, 99297, 98997, 98699, 98402, 98108, 97815, + 97524, 97234, 96947, 96661, 96376, 96094, 95813, 95534, 95256, 94980, 94705, 94432, + 94161, 93891, 93623, 93356, 93091, 92827, 92565, 92304, 92045, 91787, 91531, 91276, + 91022, 90770, 90519, 90270, 90022, 89775, 89530, 89286, 89043, 88802, 88562, 88323, + 88086, 87850, 87615, 87381, 87149, 86918, 86688, 86459, 86232, 86005, 85780, 85556, + 85333, 85112, 84891, 84672, 84454, 84237, 84021, 83806, 83592, 83379, 83168, 82957, + 82747, 82539, 82332, 82125, 81920, 81716, 81512, 81310, 81109, 80909, 80709, 80511, + 80314, 80117, 79922, 79727, 79534, 79341, 79150, 78959, 78769, 78580, 78392, 78205, + 78019, 77834, 77649, 77466, 77283, 77101, 76920, 76740, 76561, 76382, 76205, 76028, + 75852, 75677, 75502, 75329, 75156, 74984, 74813, 74642, 74473, 74304, 74136, 73968, + 73802, 73636, 73471, 73306, 73143, 72980, 72818, 72656, 72496, 72336, 72176, 72018, + 71860, 71702, 71546, 71390, 71235, 71080, 70926, 70773, 70621, 70469, 70318, 70167, + 70017, 69868, 69719, 69571, 69424, 69277, 69131, 68985, 68840, 68696, 68552, 68409, + 68267, 68125, 67983, 67843, 67702, 67563, 67424, 67285, 67148, 67010, 66873, 66737, + 66602, 66467, 66332, 66198, 66065, 65932, 65799, 65667, 65536, 65405, 65275, 65145, + 65016, 64887, 64759, 64631, 64504, 64377, 64251, 64125}; + +public: + EcalEBPhase2TimeReconstructor(bool debug); + virtual ~EcalEBPhase2TimeReconstructor(); + virtual void process(std::vector &addout, std::vector &RecoOutput, std::vector &output); + void setParameters(uint32_t raw, + const EcalEBPhase2TPGTimeWeightIdMap *ecaltpgTimeWeightMap, + const EcalTPGWeightGroup *ecaltpgWeightGroup); +}; + +#endif diff --git a/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TrigPrimAlgo.h b/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TrigPrimAlgo.h new file mode 100644 index 0000000000000..a0dad15d02e26 --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TrigPrimAlgo.h @@ -0,0 +1,217 @@ +#ifndef SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBPhase2TrigPrimAlgo_h +#define SimCalorimetry_EcalEBTrigPrimAlgos_EcalEBPhase2TrigPrimAlgo_h +/** \class EcalEBPhase2TrigPrimAlgo +\author L. Lutton, N. Marinelli - Univ. of Notre Dame + Description: forPhase II + It uses the new Phase2 digis based onthe new EB electronics + This is the main algo which plugs in all the subcomponents for the + amplitude and time measurement and the spike flagging +*/ + +#include +#include +#include + +#include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h" +#include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h" +#include "DataFormats/EcalDetId/interface/EcalTriggerElectronicsId.h" +#include "DataFormats/Common/interface/SortedCollection.h" +#include "DataFormats/EcalDigi/interface/EcalDigiCollections.h" + +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" +#include "Geometry/CaloGeometry/interface/CaloCellGeometry.h" +#include "DataFormats/EcalDigi/interface/EcalDataFrame_Ph2.h" +#include "CondFormats/EcalObjects/interface/EcalLiteDTUPedestals.h" + +#include "SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2Linearizer.h" +#include "SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2AmplitudeReconstructor.h" +#include "SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TimeReconstructor.h" +#include "SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2SpikeTagger.h" +#include "SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TPFormatter.h" + +#include +#include + +class EcalTrigTowerDetId; +class ETPCoherenceTest; +class EcalEBPhase2TriggerPrimitiveSample; +class CaloSubdetectorGeometry; +class EBDataFrame_Ph2; + +class EcalEBPhase2TrigPrimAlgo { +public: + explicit EcalEBPhase2TrigPrimAlgo(const EcalTrigTowerConstituentsMap *eTTmap, + const CaloGeometry *theGeometry, + int binofmax, + bool debug); + + virtual ~EcalEBPhase2TrigPrimAlgo(); + + void run(const EBDigiCollectionPh2 *col, EcalEBPhase2TrigPrimDigiCollection &result); + + void setPointers(const EcalLiteDTUPedestalsMap *ecaltpPed, + const EcalEBPhase2TPGLinearizationConstMap *ecaltpLin, + const EcalTPGCrystalStatus *ecaltpgBadX, + const EcalEBPhase2TPGAmplWeightIdMap *ecaltpgAmplWeightMap, + const EcalEBPhase2TPGTimeWeightIdMap *ecaltpgTimeWeightMap, + const EcalTPGWeightGroup *ecaltpgWeightGroup) { + ecaltpPed_ = ecaltpPed; + ecaltpgBadX_ = ecaltpgBadX; + ecaltpLin_ = ecaltpLin; + ecaltpgAmplWeightMap_ = ecaltpgAmplWeightMap; + ecaltpgTimeWeightMap_ = ecaltpgTimeWeightMap; + ecaltpgWeightGroup_ = ecaltpgWeightGroup; + } + +private: + //old void init(const edm::EventSetup & setup); + void init(); + template + void initStructures(std::vector > > > &towMap); + template + void clean(std::vector > > > &towerMap); + + void fillMap(EBDigiCollectionPh2 const *col, + std::vector > > > &towerMap); + + int findStripNr(const EBDetId &id); + + int getIndex(const EBDigiCollectionPh2 *, EcalTrigTowerDetId &id) { return id.hashedIndex(); } + // mind that eta is continuous between barrel+endcap + // int getIndex(const EEDigiCollectionPh2 *, EcalTrigTowerDetId& id) { + // int ind=(id.ietaAbs()-18)*72 + id.iphi(); + // if (id.zside()<0) ind+=792; + // return ind; + // } + + const EcalTrigTowerConstituentsMap *eTTmap_ = nullptr; + const CaloGeometry *theGeometry_ = nullptr; + + int binOfMaximum_; + int maxNrSamples_; + bool debug_; + + int nrTowers_; // nr of towers found by fillmap method + static const unsigned int maxNrTowers_; + static const unsigned int nrSamples_; + + // data structures kept during the whole run + std::vector > striptp_; + std::vector > > > towerMapEB_; + std::vector > hitTowers_; + std::vector towtp_; + std::vector towtp2_; + + enum { nbMaxStrips_ = 5 }; + enum { nbMaxXtals_ = 5 }; + + const EcalElectronicsMapping *theMapping_; + + EcalEBPhase2Linearizer *linearizer_; + + EcalEBPhase2AmplitudeReconstructor *amplitude_reconstructor_; + EcalEBPhase2TimeReconstructor *time_reconstructor_; + EcalEBPhase2SpikeTagger *spike_tagger_; + EcalEBPhase2TPFormatter *tpFormatter_; + + // + + const EcalLiteDTUPedestalsMap *ecaltpPed_; + const EcalTPGCrystalStatus *ecaltpgBadX_; + + const EcalTPGWeightGroup *ecaltpgWeightGroup_; + const EcalEBPhase2TPGLinearizationConstMap *ecaltpLin_; + const EcalEBPhase2TPGAmplWeightIdMap *ecaltpgAmplWeightMap_; + const EcalEBPhase2TPGTimeWeightIdMap *ecaltpgTimeWeightMap_; + + EcalEBPhase2Linearizer *getLinearizer() const { return linearizer_; } + std::vector lin_out_; + // + EcalEBPhase2AmplitudeReconstructor *getAmplitudeFinder() const { return amplitude_reconstructor_; } + std::vector filt_out_; + std::vector time_out_; + std::vector amp_out_; + std::vector outEt_; + std::vector outTime_; + + EcalEBPhase2TimeReconstructor *getTimeFinder() const { return time_reconstructor_; } + EcalEBPhase2SpikeTagger *getSpikeTagger() const { return spike_tagger_; } + EcalEBPhase2TPFormatter *getTPFormatter() const { return tpFormatter_; } + + // +}; + +template +void EcalEBPhase2TrigPrimAlgo::clean(std::vector > > > &towMap) { + // clean internal data structures + for (unsigned int i = 0; i < maxNrTowers_; ++i) + for (int j = 0; j < nbMaxStrips_; ++j) + (towMap[i])[j].first = 0; + return; +} + +inline void EcalEBPhase2TrigPrimAlgo::fillMap( + EBDigiCollectionPh2 const *col, std::vector > > > &towerMap) + +{ + // implementation for Barrel + if (col) { + nrTowers_ = 0; + for (unsigned int i = 0; i < col->size(); ++i) { + EBDigiCollectionPh2::Digi samples((*col)[i]); + EcalTrigTowerDetId coarser = (*eTTmap_).towerOf(samples.id()); + int index = getIndex(col, coarser); + EBDetId id = samples.id(); + int stripnr = findStripNr(id); + + int filled = 0; + for (unsigned int ij = 0; ij < towerMap[index].size(); ++ij) + filled += towerMap[index][ij].first; + if (!filled) { + hitTowers_[nrTowers_++] = std::pair(index, coarser); + } + + //FIXME: temporary protection + int ncryst = towerMap[index][stripnr - 1].first; + if (ncryst >= nbMaxXtals_) { + continue; + } + ((towerMap[index])[stripnr - 1].second)[ncryst] = samples; + (towerMap[index])[stripnr - 1].first++; + } + + if (debug_) + LogDebug("") << "fillMap" + << "[EcalEBPhase2TrigPrimAlgo] (found " << col->size() << " frames in " << towerMap.size() + << " towers) " << std::endl; + } else { + if (debug_) + LogDebug("EcalEBPhase2TrigPrimAlgo") << "FillMap - FillMap Collection size=0 !!!!" << std::endl; + ; + } +} + +template +void EcalEBPhase2TrigPrimAlgo::initStructures(std::vector > > > &towMap) { + //initialise internal data structures + + std::vector vec0(nbMaxXtals_); + std::vector > > vec1(nbMaxStrips_); + for (int i = 0; i < nbMaxStrips_; ++i) + vec1[i] = std::pair >(0, vec0); + towMap.resize(maxNrTowers_); + for (unsigned int i = 0; i < maxNrTowers_; ++i) + towMap[i] = vec1; + + std::vector vecint(maxNrSamples_); + striptp_.resize(nbMaxStrips_); + for (int i = 0; i < nbMaxStrips_; ++i) + striptp_[i] = vecint; +} + +#endif diff --git a/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2AmplitudeReconstructor.cc b/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2AmplitudeReconstructor.cc new file mode 100644 index 0000000000000..2ac137f06f712 --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2AmplitudeReconstructor.cc @@ -0,0 +1,140 @@ +#include +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeightIdMap.h" +#include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h" +#include "DataFormats/EcalDigi/interface/EcalConstants.h" +#include "CondFormats/EcalObjects/interface/EcalTPGGroups.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include + +EcalEBPhase2AmplitudeReconstructor::EcalEBPhase2AmplitudeReconstructor(bool debug) + : debug_(debug), inputsAlreadyIn_(0), shift_(13) {} + +EcalEBPhase2AmplitudeReconstructor::~EcalEBPhase2AmplitudeReconstructor() {} + +int EcalEBPhase2AmplitudeReconstructor::setInput(int input) { + if (input > 0X3FFF) { + edm::LogError("EcalEBPhase2AmplitudeReconstructor") << "ERROR IN INPUT OF AMPLITUDE FILTER" << std::endl; + return -1; + } + + if (inputsAlreadyIn_ < maxSamplesUsed_) { + if (debug_) + LogDebug("") << " EcalEBPhase2AmplitudeReconstructor::setInput inputsAlreadyIn_<5 input " << input << std::endl; + + buffer_[inputsAlreadyIn_] = input; + inputsAlreadyIn_++; + } else { + for (int i = 0; i < (maxSamplesUsed_ - 1); i++) { + buffer_[i] = buffer_[i + 1]; + if (debug_) + LogDebug("") << " EcalEBPhase2AmplitudeReconstructor::setInput inputsAlreadyIn buffer " << buffer_[i] + << std::endl; + } + buffer_[maxSamplesUsed_ - 1] = input; + } + return 1; +} + +void EcalEBPhase2AmplitudeReconstructor::process(std::vector &linout, std::vector &output) { + inputsAlreadyIn_ = 0; + for (unsigned int i = 0; i < maxSamplesUsed_; i++) { + buffer_[i] = 0; + } + + for (unsigned int i = 0; i < linout.size(); i++) { + setInput(linout[i]); + if (debug_) { + for (unsigned int j = 0; j < maxSamplesUsed_; j++) { + LogDebug("") << " buffer_ " << buffer_[j]; + } + LogDebug("") << " " << std::endl; + } + + if (i == (maxSamplesUsed_ - 1)) { + process(); + output[0] = processedOutput_; + } else if (i == (ecalPh2::sampleSize - 1)) { + process(); + output[1] = processedOutput_; + } + } + return; +} + +void EcalEBPhase2AmplitudeReconstructor::process() { + processedOutput_ = 0; + if (inputsAlreadyIn_ < maxSamplesUsed_) + return; + int64_t tmpIntOutput = 0; + for (int i = 0; i < maxSamplesUsed_; i++) { + tmpIntOutput += (weights_[i] * buffer_[i]); + if (debug_) + LogDebug("") << " AmplitudeFilter buffer " << buffer_[i] << " weight " << weights_[i] << std::endl; + } + if (tmpIntOutput < 0) + tmpIntOutput = 0; + tmpIntOutput = tmpIntOutput >> shift_; + if (debug_) + LogDebug("") << " AmplitudeFilter tmpIntOutput " << tmpIntOutput << " shift_ " << shift_ << std::endl; + if (tmpIntOutput > 0X1FFF) + tmpIntOutput = 0X1FFF; + uint output = tmpIntOutput; // should be 13 bit uint at this point + processedOutput_ = output; + if (debug_) + LogDebug("") << " AmplitudeFilter processedOutput_ " << processedOutput_ << std::endl; +} + +void EcalEBPhase2AmplitudeReconstructor::setParameters(uint32_t raw, + const EcalEBPhase2TPGAmplWeightIdMap *ecaltpgWeightMap, + const EcalTPGWeightGroup *ecaltpgWeightGroup) { + uint32_t params_[maxSamplesUsed_]; + const EcalTPGGroups::EcalTPGGroupsMap &groupmap = ecaltpgWeightGroup->getMap(); + if (debug_) + LogDebug("") << " EcalEBPhase2AmplitudeReconstructor::setParameters groupmap size " << groupmap.size() + << " channel ID " << raw << std::endl; + EcalTPGGroups::EcalTPGGroupsMapItr it = groupmap.find(raw); + if (it != groupmap.end()) { + uint32_t weightid = (*it).second; + + const EcalEBPhase2TPGAmplWeightIdMap::EcalEBPhase2TPGAmplWeightMap &weightmap = ecaltpgWeightMap->getMap(); + EcalEBPhase2TPGAmplWeightIdMap::EcalEBPhase2TPGAmplWeightMapItr itw = weightmap.find(weightid); + + (*itw).second.getValues(params_[0], + params_[1], + params_[2], + params_[3], + params_[4], + params_[5], + params_[6], + params_[7], + params_[8], + params_[9], + params_[10], + params_[11]); + + if (debug_) + LogDebug("") << " EcalEBPhase2AmplitudeReconstructor::setParameters weights after the map " << params_[0] << " " + << params_[1] << " " << params_[2] << " " << params_[3] << " " << params_[4] << " " << params_[5] + << " " << params_[6] << " " << params_[7] << " " << params_[8] << " " << params_[9] << " " + << params_[10] << " " << params_[11] << std::endl; + + // we have to transform negative coded in 13 bits into negative coded in 32 bits + // maybe this should go into the getValue method?? + + for (int i = 0; i < maxSamplesUsed_; ++i) { + weights_[i] = (params_[i] & 0x1000) ? (int)(params_[i] | 0xfffff000) : (int)(params_[i]); + } + + if (debug_) { + for (int i = 0; i < maxSamplesUsed_; ++i) { + LogDebug("") << " EcalEBPhase2AmplitudeReconstructor::setParameters weights after the cooking " << weights_[i] + << std::endl; + } + LogDebug("") << std::endl; + } + + } else + edm::LogWarning("EcalTPG") + << " EcalEBPhase2AmplitudeReconstructor::setParameters could not find EcalTPGGroupsMap entry for " << raw; +} diff --git a/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2Linearizer.cc b/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2Linearizer.cc new file mode 100644 index 0000000000000..2802081a81ffa --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2Linearizer.cc @@ -0,0 +1,167 @@ +#include + +//#include + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +EcalEBPhase2Linearizer::EcalEBPhase2Linearizer(bool debug) + : debug_(debug), init_(false), peds_(nullptr), badXStatus_(nullptr) {} + +EcalEBPhase2Linearizer::~EcalEBPhase2Linearizer() { + if (init_) { + for (int i = 0; i < (int)vectorbadXStatus_.size(); i++) { + delete vectorbadXStatus_[i]; + } + } +} + +void EcalEBPhase2Linearizer::setParameters(EBDetId detId, + const EcalLiteDTUPedestalsMap *ecaltpPed, + const EcalEBPhase2TPGLinearizationConstMap *ecaltpLin, + const EcalTPGCrystalStatus *ecaltpBadX) + +{ + EcalLiteDTUPedestalsMap::const_iterator itped = ecaltpPed->getMap().find(detId); + if (itped != ecaltpPed->end()) + peds_ = &(*itped); + else + edm::LogError("EcalEBPhase2Linearizer") << " could not find EcalLiteDTUPedestal entry for " << detId << std::endl; + + const EcalEBPhase2TPGLinearizationConstMap &linMap = ecaltpLin->getMap(); + EcalEBPhase2TPGLinearizationConstMapIterator it = linMap.find(detId.rawId()); + if (it != linMap.end()) { + linConsts_ = &(*it); + } else + edm::LogError("EcalEBPhase2Linearizer") + << " could not find EcalEBPhase2TPGLinearizationConstMap entry for " << detId.rawId() << std::endl; + + const EcalTPGCrystalStatusMap &badXMap = ecaltpBadX->getMap(); + EcalTPGCrystalStatusMapIterator itbadX = badXMap.find(detId.rawId()); + if (itbadX != badXMap.end()) { + badXStatus_ = &(*itbadX); + } else { + edm::LogWarning("EcalTPG") << " could not find EcalTPGCrystalStatusMap entry for " << detId.rawId(); + badXStatus_ = new EcalTPGCrystalStatusCode(); + vectorbadXStatus_.push_back(&(*badXStatus_)); + init_ = true; + } +} + +int EcalEBPhase2Linearizer::doOutput() { + int tmpIntOut; + if (uncorrectedSample_) { + tmpIntOut = (uncorrectedSample_ - base_ + I2CSub_); //Substract base. Add I2C + } else { + tmpIntOut = 0; + } + if (tmpIntOut < 0) { + tmpIntOut = 0; + } + uint output = tmpIntOut; + output = (output * mult_) >> shift_; + // protect against saturation + // ........... + + return output; +} + +int EcalEBPhase2Linearizer::setInput(const EcalLiteDTUSample &RawSam) + +{ + uncorrectedSample_ = RawSam.adc(); //uncorrectedSample_ + gainID_ = RawSam.gainId(); + + base_ = peds_->mean(gainID_); + + if (gainID_ == 0) { + mult_ = linConsts_->mult_x10; + shift_ = linConsts_->shift_x10; + I2CSub_ = linConsts_->i2cSub_x10; + } else { + mult_ = linConsts_->mult_x1; + shift_ = linConsts_->shift_x1; + I2CSub_ = linConsts_->i2cSub_x1; + } + + return 1; +} + +void EcalEBPhase2Linearizer::process(const EBDigiCollectionPh2::Digi &df, std::vector &output_percry) { + //We know a tower numbering is: // S1 S2 S3 S4 S5 + + // 4 5 14 15 24 + // 3 6 13 16 23 + // 2 7 12 17 22 + // 1 8 11 18 21 + // 0 9 10 19 20 + + for (int i = 0; i < df.size(); i++) { + EcalLiteDTUSample thisSample = df[i]; + setInput(thisSample); + output_percry[i] = doOutput(); + } + + if (debug_) { + LogDebug("EcalEBPhase2Linearizer") << " mult " + << " "; + for (int i = 0; i < df.size(); i++) { + EcalLiteDTUSample thisSample = df[i]; + setInput(thisSample); + LogDebug("") << mult_ << " "; + } + LogDebug("") << " " << std::endl; + + LogDebug("") << " gainID " + << " "; + for (int i = 0; i < df.size(); i++) { + EcalLiteDTUSample thisSample = df[i]; + setInput(thisSample); + LogDebug("") << gainID_ << " "; + } + LogDebug("") << " " << std::endl; + + LogDebug("") << " Ped " + << " "; + for (int i = 0; i < df.size(); i++) { + EcalLiteDTUSample thisSample = df[i]; + setInput(thisSample); + LogDebug("") << base_ << " "; + } + LogDebug("") << " " << std::endl; + + LogDebug("") << " i2c " + << " "; + for (int i = 0; i < df.size(); i++) { + EcalLiteDTUSample thisSample = df[i]; + setInput(thisSample); + LogDebug("") << I2CSub_ << " "; + } + LogDebug("") << " " << std::endl; + + LogDebug("") << " shift " + << " "; + for (int i = 0; i < df.size(); i++) { + EcalLiteDTUSample thisSample = df[i]; + setInput(thisSample); + LogDebug("") << shift_ << " "; + } + LogDebug("") << " " << std::endl; + + LogDebug("") << " lin out " + << " "; + for (int i = 0; i < df.size(); i++) { + LogDebug("") << output_percry[i] << " "; + } + + LogDebug("") << " " << std::endl; + + LogDebug("") << " EcalEBPhase2Linearizer::process(const .. Final output " << std::endl; + LogDebug("") << " output_percry " + << " "; + for (int i = 0; i < df.size(); i++) { + LogDebug("") << output_percry[i] << " "; + } + LogDebug("") << " " << std::endl; + } + return; +} diff --git a/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2SpikeTagger.cc b/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2SpikeTagger.cc new file mode 100644 index 0000000000000..d430c093bfe52 --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2SpikeTagger.cc @@ -0,0 +1,53 @@ +#include + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +EcalEBPhase2SpikeTagger::EcalEBPhase2SpikeTagger(bool debug) : debug_(debug) {} + +EcalEBPhase2SpikeTagger::~EcalEBPhase2SpikeTagger() {} + +void EcalEBPhase2SpikeTagger::setParameters(EBDetId detId, + const EcalLiteDTUPedestalsMap* ecaltpPed, + const EcalEBPhase2TPGLinearizationConstMap* ecaltpLin, + const EcalTPGCrystalStatus* ecaltpBadX) + +{ + if (debug_) + LogDebug("") << " EcalEBPhase2SpikeTagger::setParameters " << std::endl; + + EcalLiteDTUPedestalsMap::const_iterator itped = ecaltpPed->getMap().find(detId); + if (itped != ecaltpPed->end()) { + peds_ = &(*itped); + } else { + edm::LogError("EcalEBPhase2SpikeTagger::setParameters") + << " could not find EcalLiteDTUPedestal entry for " << detId; + throw cms::Exception("EcalEBPhase2SpikeTagger::setParameters could not find pedestals"); + } + + const EcalEBPhase2TPGLinearizationConstMap& linMap = ecaltpLin->getMap(); + EcalEBPhase2TPGLinearizationConstMapIterator it = linMap.find(detId.rawId()); + if (it != linMap.end()) { + linConsts_ = &(*it); + } else { + edm::LogError("EcalEBPhase2SpikeTagger::setParameters") + << " could not find EcalEBPhase2TPGLinearizationConstMap entry for " << detId.rawId(); + throw cms::Exception("EcalEBPhase2SpikeTagger::setParameters could not find pedestals"); + } +} + +bool EcalEBPhase2SpikeTagger::process(const std::vector& linInput) { + bool isASpike; + isASpike = false; + + if (debug_) { + LogDebug("") << "EcalEBPhase2SpikeTagger::process linearized digis " << std::endl; + for (unsigned int i = 0; i < linInput.size(); i++) { + LogDebug("") << " " << std::dec << linInput[i]; + } + LogDebug("") << std::endl; + } + + // dummy for now. It needs the algorythm to be implememted/plugged in here + + return isASpike; +} diff --git a/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2TPFormatter.cc b/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2TPFormatter.cc new file mode 100644 index 0000000000000..610809ae58f34 --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2TPFormatter.cc @@ -0,0 +1,38 @@ +#include +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include + +EcalEBPhase2TPFormatter::EcalEBPhase2TPFormatter(bool debug) : debug_(debug) {} + +EcalEBPhase2TPFormatter::~EcalEBPhase2TPFormatter() {} + +void EcalEBPhase2TPFormatter::process(std::vector &, + std::vector &time, + std::vector &outEt, + std::vector &outTime) { + unsigned int size = amp.size(); + outEt.resize(size); + outTime.resize(size); + + for (unsigned int i = 0; i < size; ++i) { + outEt[i] = amp[i]; + outTime[i] = time[i]; + } + + for (unsigned int i = 0; i < size; ++i) { + // this is the energy compression to 12 bits to go in the DF. To be done as last thing before building the TP + //Bit shift by 1 to go from 13 bits to 12 + outEt[i] = outEt[i] >> 1; + if (outEt[i] > 0xFFF) + outEt[i] = 0xFFF; + } + + for (unsigned int i = 0; i < size; ++i) { + // this is the time compression to 5 bits to go in the DF. + outTime[i] = outTime[i] >> 6; + if (outTime[i] > 0xf) + outTime[i] = 0xf; + else if (outTime[i] < -0x10) + outTime[i] = -0x10; + } +} diff --git a/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2TimeReconstructor.cc b/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2TimeReconstructor.cc new file mode 100644 index 0000000000000..6349a2ec60950 --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2TimeReconstructor.cc @@ -0,0 +1,174 @@ +#include +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeightIdMap.h" +#include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h" +#include "DataFormats/EcalDigi/interface/EcalConstants.h" +#include "CondFormats/EcalObjects/interface/EcalTPGGroups.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include + +EcalEBPhase2TimeReconstructor::EcalEBPhase2TimeReconstructor(bool debug) + : debug_(debug), inputsAlreadyIn_(0), shift_(maxSamplesUsed_) {} + +EcalEBPhase2TimeReconstructor::~EcalEBPhase2TimeReconstructor() {} + +int EcalEBPhase2TimeReconstructor::setInput(int input) { + if (input > 0X7FFF) { + edm::LogError("EcalEBPhase2TimeReconstructor::setInput") << "ERROR IN INPUT OF TIME FILTER" << std::endl; + return -1; + } + if (inputsAlreadyIn_ < maxSamplesUsed_) { + if (debug_) + LogDebug("") << " EcalEBPhase2TimeReconstructor::setInput inputsAlreadyIn_<5 input " << input << std::endl; + + buffer_[inputsAlreadyIn_] = input; + inputsAlreadyIn_++; + } else { + for (int i = 0; i < (maxSamplesUsed_ - 1); i++) { + buffer_[i] = buffer_[i + 1]; + if (debug_) + LogDebug("") << " EcalEBPhase2TimeReconstructor::setInput inputsAlreadyIn buffer " << buffer_[i] << std::endl; + } + buffer_[maxSamplesUsed_ - 1] = input; + inputsAlreadyIn_++; + } + return 1; +} + +void EcalEBPhase2TimeReconstructor::process(std::vector &addout, + std::vector &RecoOutput, + std::vector &output) { + inputsAlreadyIn_ = 0; + for (unsigned int i = 0; i < maxSamplesUsed_; i++) { + buffer_[i] = 0; + } + + //Taking in the results of the amplitude reconstruction + //Bit shifting them for use as index of invAmpAr_ lookup table + // move input amplitude (13 bits) to 9 bits to use as array index + + ampIn_[0] = ampRecoOutput[0] >> 4; + ampIn_[1] = ampRecoOutput[1] >> 4; + + for (unsigned int i = 0; i < addout.size(); i++) { + setInput(addout[i]); + + if (debug_) { + LogDebug("") << " EcalEBPhase2TimeReconstructor::process(std::vector buffer_ " << std::endl; + + for (unsigned int j = 0; j < maxSamplesUsed_; j++) { + LogDebug("") << " buffer_ " << buffer_[j]; + } + LogDebug("") << " " << std::endl; + } + + if (i == (maxSamplesUsed_ - 1)) { + if (debug_) + LogDebug("") << " EcalEBPhase2TimeReconstructor::process(std::vector) i = 11 " << std::endl; + process(); + if (debug_) + LogDebug("") << " EcalEBPhase2TimeReconstructor::process(std::vector) after process() " + << processedOutput_ << std::endl; + output[0] = processedOutput_; + if (debug_) + LogDebug("") << " EcalEBPhase2TimeReconstructor::process(std::vector) after setting the output " + << output[0] << std::endl; + } else if (i == (ecalPh2::sampleSize - 1)) { + if (debug_) + LogDebug("") << " EcalEBPhase2TimeReconstructor::process(std::vector) i = 15 " << std::endl; + process(); + output[1] = processedOutput_; + } + } + + return; +} + +void EcalEBPhase2TimeReconstructor::process() { + //UB FIXME: 5 + processedOutput_ = 0; + if (inputsAlreadyIn_ < 12) + return; + int64_t output = 0; + for (int i = 0; i < 12; i++) { + output += (weights_[i] * buffer_[i]); + if (debug_) + LogDebug("") << " TimeFilter buffer " << buffer_[i] << " weight " << weights_[i] << " output " << output + << std::endl; + } + output = output >> shift_; + if (debug_) + LogDebug("") << " TimeFilter local output " << output << std::endl; + //Dividing output by the result of the amplitude reconstruction via an approximation using the invAmpAr lookup table + int ampInd = 0; + if (debug_) + LogDebug("") << " inputsAlreadyIn_ " << inputsAlreadyIn_ << std::endl; + if (inputsAlreadyIn_ > 12) { + ampInd = 1; + } + + if (debug_) + LogDebug("") << " Begininning Final TimeFilter Calculation" << std::endl; + + int64_t tmpOutput = output * invAmpAr_[ampIn_[ampInd]]; + if (debug_) + LogDebug("") << " output*tmpInvAmpAr " << tmpOutput << std::endl; + + output = tmpOutput >> 20; + if (debug_) + LogDebug("") << " output after bit shift " << output << std::endl; + + if (output < -1024) + output = -1023; + else if (output > 1024) + output = 1023; + if (debug_) + LogDebug("") << " output after if/else " << output << std::endl; + processedOutput_ = output; + + if (debug_) + LogDebug("") << " TimeFilter final output " << processedOutput_ << std::endl; +} + +void EcalEBPhase2TimeReconstructor::setParameters(uint32_t raw, + const EcalEBPhase2TPGTimeWeightIdMap *ecaltpgWeightMap, + const EcalTPGWeightGroup *ecaltpgWeightGroup) { + uint32_t params_[12]; + const EcalTPGGroups::EcalTPGGroupsMap &groupmap = ecaltpgWeightGroup->getMap(); + if (debug_) + LogDebug("") << " EcalEBPhase2TimeReconstructor::setParameters groupmap size " << groupmap.size() << std::endl; + EcalTPGGroups::EcalTPGGroupsMapItr it = groupmap.find(raw); + if (it != groupmap.end()) { + uint32_t weightid = (*it).second; + const EcalEBPhase2TPGTimeWeightIdMap::EcalEBPhase2TPGTimeWeightMap &weightmap = ecaltpgWeightMap->getMap(); + EcalEBPhase2TPGTimeWeightIdMap::EcalEBPhase2TPGTimeWeightMapItr itw = weightmap.find(weightid); + + (*itw).second.getValues(params_[0], + params_[1], + params_[2], + params_[3], + params_[4], + params_[5], + params_[6], + params_[7], + params_[8], + params_[9], + params_[10], + params_[11]); + + if (debug_) + LogDebug("") << " EcalEBPhase2TimeReconstructor::setParameters time weights after the map " << params_[0] << " " + << params_[1] << " " << params_[2] << " " << params_[3] << " " << params_[4] << " " << params_[5] + << " " << params_[6] << " " << params_[7] << " " << params_[8] << " " << params_[9] << " " + << params_[10] << " " << params_[11] << std::endl; + + // we have to transform negative coded in 16 bits into negative coded in 32 bits + // maybe this should go into the getValue method?? + + for (int i = 0; i < 12; ++i) { + weights_[i] = (params_[i] & 0x8000) ? (int)(params_[i] | 0xffff8000) : (int)(params_[i]); + } + + } else + edm::LogWarning("EcalTPG") + << " EcalEBPhase2TimeReconstructor::setParameters could not find EcalTPGGroupsMap entry for " << raw; +} diff --git a/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2TrigPrimAlgo.cc b/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2TrigPrimAlgo.cc new file mode 100644 index 0000000000000..7aa5558cdd08f --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimAlgos/src/EcalEBPhase2TrigPrimAlgo.cc @@ -0,0 +1,294 @@ +#include +#include +#include +#include + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h" +#include "Geometry/EcalMapping/interface/EcalMappingRcd.h" +#include "Geometry/EcalAlgo/interface/EcalBarrelGeometry.h" + +#include "SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TrigPrimAlgo.h" + +#include "DataFormats/EcalDetId/interface/EcalSubdetector.h" +#include "DataFormats/EcalDigi/interface/EBDataFrame_Ph2.h" +#include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h" +#include "DataFormats/EcalDetId/interface/EBDetId.h" +#include "DataFormats/EcalDetId/interface/EcalTriggerElectronicsId.h" + +#include "CondFormats/EcalObjects/interface/EcalTPGPedestals.h" +#include "CondFormats/DataRecord/interface/EcalTPGPedestalsRcd.h" + +#include "DataFormats/EcalDigi/interface/EcalConstants.h" + +#include +#include + +//---------------------------------------------------------------------- + +const unsigned int EcalEBPhase2TrigPrimAlgo::nrSamples_ = + ecalPh2::sampleSize; // set to 16 samples, might change (less than 16) in the future +const unsigned int EcalEBPhase2TrigPrimAlgo::maxNrTowers_ = 2448; // number of towers in EB + +EcalEBPhase2TrigPrimAlgo::EcalEBPhase2TrigPrimAlgo(const EcalTrigTowerConstituentsMap *eTTmap, + const CaloGeometry *theGeometry, + int binofmax, + bool debug) + : eTTmap_(eTTmap), + theGeometry_(theGeometry), + binOfMaximum_(binofmax), + debug_(debug) + +{ + maxNrSamples_ = ecalPh2::sampleSize; + this->init(); +} + +void EcalEBPhase2TrigPrimAlgo::init() { + theMapping_ = new EcalElectronicsMapping(); + // initialise data structures + initStructures(towerMapEB_); + hitTowers_.resize(maxNrTowers_); + + linearizer_ = new EcalEBPhase2Linearizer(debug_); + lin_out_.resize(maxNrSamples_); + + amplitude_reconstructor_ = new EcalEBPhase2AmplitudeReconstructor(debug_); + filt_out_.resize(maxNrSamples_); + + tpFormatter_ = new EcalEBPhase2TPFormatter(debug_); + outEt_.resize(maxNrSamples_); + outTime_.resize(maxNrSamples_); + + // + + time_reconstructor_ = new EcalEBPhase2TimeReconstructor(debug_); + time_out_.resize(maxNrSamples_); + spike_tagger_ = new EcalEBPhase2SpikeTagger(debug_); +} +//---------------------------------------------------------------------- + +EcalEBPhase2TrigPrimAlgo::~EcalEBPhase2TrigPrimAlgo() { + delete linearizer_; + delete amplitude_reconstructor_; + delete time_reconstructor_; + delete spike_tagger_; + delete tpFormatter_; + delete theMapping_; +} + +void EcalEBPhase2TrigPrimAlgo::run(EBDigiCollectionPh2 const *digi, EcalEBPhase2TrigPrimDigiCollection &result) { + if (debug_) + LogDebug("") << " EcalEBPhase2TrigPrimAlgo: digi size " << digi->size() << std::endl; + + EcalEBPhase2TriggerPrimitiveDigi tp; + int firstSample = binOfMaximum_ - 1 - nrSamples_ / 2; + int lastSample = binOfMaximum_ - 1 + nrSamples_ / 2; + + if (debug_) { + LogDebug("") << " binOfMaximum_ " << binOfMaximum_ << " nrSamples_" << nrSamples_ << std::endl; + LogDebug("") << " first sample " << firstSample << " last " << lastSample << std::endl; + } + + clean(towerMapEB_); + fillMap(digi, towerMapEB_); + + int iChannel = 0; + int nXinBCP = 0; + for (int itow = 0; itow < nrTowers_; ++itow) { + int index = hitTowers_[itow].first; + const EcalTrigTowerDetId &thisTower = hitTowers_[itow].second; + if (debug_) + LogDebug("") << " Data for TOWER num " << itow << " index " << index << " TowerId " << thisTower << " zside " + << thisTower.zside() << " ieta " << thisTower.ieta() << " iphi " << thisTower.iphi() << " size " + << towerMapEB_[itow].size() << std::endl; + + // loop over all strips assigned to this trigger tower + int nxstals = 0; + for (unsigned int iStrip = 0; iStrip < towerMapEB_[itow].size(); ++iStrip) { + if (debug_) + LogDebug("") << " Data for STRIP num " << iStrip << std::endl; + std::vector &dataFrames = + (towerMapEB_[index])[iStrip].second; //vector of dataframes for this strip, size; nr of crystals/strip + + nxstals = (towerMapEB_[index])[iStrip].first; + if (nxstals <= 0) + continue; + if (debug_) + LogDebug("") << " Number of xTals " << nxstals << std::endl; + + //const EcalTriggerElectronicsId elId = theMapping_->getTriggerElectronicsId(dataFrames[0].id()); + + // loop over the xstals in a strip + + for (int iXstal = 0; iXstal < nxstals; iXstal++) { + const EBDetId &myid = dataFrames[iXstal].id(); + + nXinBCP++; + if (debug_) { + LogDebug("") << " Data for TOWER num " << itow << " index " << index << " TowerId " << thisTower << " size " + << towerMapEB_[itow].size() << std::endl; + LogDebug("") << "nXinBCP " << nXinBCP << " myid rawId " << myid.rawId() << " xTal iEta " << myid.ieta() + << " iPhi " << myid.iphi() << std::endl; + } + + tp = EcalEBPhase2TriggerPrimitiveDigi(myid); + tp.setSize(nrSamples_); + + iChannel++; + if (debug_) { + LogDebug("") << " " << std::endl; + LogDebug("") << " ****** iChannel " << iChannel << std::endl; + for (int i = 0; i < dataFrames[iXstal].size(); i++) { + LogDebug("") << " " << dataFrames[iXstal][i].adc(); + } + LogDebug("") << " " << std::endl; + } + + if (debug_) { + LogDebug("") << std::endl; + EBDetId id = dataFrames[iXstal].id(); + LogDebug("") << "iXstal= " << iXstal << std::endl; + LogDebug("") << "iXstal= " << iXstal << " id " << id << " EcalDataFrame_Ph2 is: " << std::endl; + for (int i = 0; i < dataFrames[iXstal].size(); i++) { + LogDebug("") << " " << std::dec << dataFrames[iXstal][i].adc(); + } + LogDebug("") << std::endl; + } + + // Call the linearizer + this->getLinearizer()->setParameters(dataFrames[iXstal].id(), ecaltpPed_, ecaltpLin_, ecaltpgBadX_); + this->getLinearizer()->process(dataFrames[iXstal], lin_out_); + + for (unsigned int i = 0; i < lin_out_.size(); i++) { + if (lin_out_[i] > 0X3FFF) + lin_out_[i] = 0X3FFF; + } + + if (debug_) { + LogDebug("") << "EcalEBPhase2TrigPrimAlgo output of linearize for channel " << iXstal << std::endl; + for (unsigned int i = 0; i < lin_out_.size(); i++) { + LogDebug("") << " " << std::dec << lin_out_[i]; + } + LogDebug("") << std::endl; + } + + // call spike finder right after the linearizer + this->getSpikeTagger()->setParameters(dataFrames[iXstal].id(), ecaltpPed_, ecaltpLin_, ecaltpgBadX_); + bool isASpike = this->getSpikeTagger()->process(lin_out_); + + //if (!isASpike) { + + // Call the amplitude reconstructor + this->getAmplitudeFinder()->setParameters(myid.rawId(), ecaltpgAmplWeightMap_, ecaltpgWeightGroup_); + this->getAmplitudeFinder()->process(lin_out_, filt_out_); + + if (debug_) { + LogDebug("") << "EcalEBPhase2TrigPrimAlgo output of amp finder is a vector of size: " << std::dec + << time_out_.size() << std::endl; + for (unsigned int ix = 0; ix < filt_out_.size(); ix++) { + LogDebug("") << std::dec << filt_out_[ix] << " "; + } + LogDebug("") << std::endl; + } + + if (debug_) { + LogDebug("") << " Ampl " + << " "; + for (unsigned int ix = 0; ix < filt_out_.size(); ix++) { + LogDebug("") << std::dec << filt_out_[ix] << " "; + } + LogDebug("") << std::endl; + } + + // call time finder + this->getTimeFinder()->setParameters(myid.rawId(), ecaltpgTimeWeightMap_, ecaltpgWeightGroup_); + this->getTimeFinder()->process(lin_out_, filt_out_, time_out_); + + if (debug_) { + LogDebug("") << " Time " + << " "; + for (unsigned int ix = 0; ix < time_out_.size(); ix++) { + LogDebug("") << std::dec << time_out_[ix] << " "; + } + LogDebug("") << std::endl; + } + + if (debug_) { + LogDebug("") << "EcalEBPhase2TrigPrimAlgo output of timefinder is a vector of size: " << std::dec + << time_out_.size() << std::endl; + for (unsigned int ix = 0; ix < time_out_.size(); ix++) { + LogDebug("") << std::dec << time_out_[ix] << " "; + } + LogDebug("") << std::endl; + } + + this->getTPFormatter()->process(filt_out_, time_out_, outEt_, outTime_); + + if (debug_) { + LogDebug("") << " compressed Et " + << " "; + for (unsigned int iSample = 0; iSample < outEt_.size(); ++iSample) { + LogDebug("") << outEt_[iSample] << " "; + } + LogDebug("") << std::endl; + + LogDebug("") << " compressed time " + << " "; + for (unsigned int iSample = 0; iSample < outEt_.size(); ++iSample) { + LogDebug("") << outTime_[iSample] << " "; + } + LogDebug("") << std::endl; + } + + if (debug_) { + LogDebug("") << " EcalEBPhase2TrigPrimAlgo after getting the formatter " << std::endl; + for (unsigned int iSample = 0; iSample < outEt_.size(); ++iSample) { + LogDebug("") << " outEt " << outEt_[iSample] << " outTime " << outTime_[iSample] << " "; + } + LogDebug("") << std::endl; + } + + // } not a spike + + // create the final TP samples + int etInADC = 0; + ; + int64_t time = -999; + int nSam = 0; + for (int iSample = 0; iSample < 16; ++iSample) { + etInADC = outEt_[iSample]; + time = outTime_[iSample]; + if (debug_) { + LogDebug("") << "TrigPrimAlgo outEt " << outEt_[iSample] << " outTime " << outTime_[iSample] << std::endl; + LogDebug("") << "TrigPrimAlgo etInADCt " << outEt_[iSample] << " outTime " << time << std::endl; + } + + tp.setSample(nSam, EcalEBPhase2TriggerPrimitiveSample(etInADC, isASpike, time)); + nSam++; + } + + result.push_back(tp); + + } // Loop over the xStals + + } //loop over strips in one tower + + if (debug_) { + if (nXinBCP > 0) + LogDebug("") << " Accepted xTals " << nXinBCP << std::endl; + } + } +} + +//---------------------------------------------------------------------- + +int EcalEBPhase2TrigPrimAlgo::findStripNr(const EBDetId &id) { + int stripnr; + int n = ((id.ic() - 1) % 100) / 20; //20 corresponds to 4 * ecal_barrel_crystals_per_strip FIXME!! + if (id.ieta() < 0) + stripnr = n + 1; + else + stripnr = nbMaxStrips_ - n; + return stripnr; +} diff --git a/SimCalorimetry/EcalEBTrigPrimProducers/plugins/EcalEBTrigPrimPhase2ESProducer.cc b/SimCalorimetry/EcalEBTrigPrimProducers/plugins/EcalEBTrigPrimPhase2ESProducer.cc new file mode 100644 index 0000000000000..6a3772fdf3ccf --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimProducers/plugins/EcalEBTrigPrimPhase2ESProducer.cc @@ -0,0 +1,722 @@ +// user include files +#include "DataFormats/EcalDigi/interface/EcalConstants.h" +#include "FWCore/Framework/interface/ESProducer.h" +#include "FWCore/Framework/interface/ModuleFactory.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/FileInPath.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +// +#include "CondFormats/DataRecord/interface/EcalTPGCrystalStatusRcd.h" +#include "CondFormats/DataRecord/interface/EcalTPGPhysicsConstRcd.h" +#include "CondFormats/DataRecord/interface/EcalTPGStripStatusRcd.h" +// commented lines are for a reminder that in future we might need to implement something alike +//#include "CondFormats/DataRecord/interface/EcalTPGSpikeRcd.h" +//#include "CondFormats/DataRecord/interface/EcalTPGTowerStatusRcd.h" +#include "CondFormats/DataRecord/interface/EcalEBPhase2TPGLinearizationConstRcd.h" +#include "CondFormats/DataRecord/interface/EcalTPGWeightGroupRcd.h" +#include "CondFormats/DataRecord/interface/EcalEBPhase2TPGAmplWeightIdMapRcd.h" +#include "CondFormats/DataRecord/interface/EcalEBPhase2TPGTimeWeightIdMapRcd.h" +#include "CondFormats/DataRecord/interface/EcalEBPhase2TPGPedestalsRcd.h" +#include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGLinearizationConst.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGPedestals.h" +#include "CondFormats/EcalObjects/interface/EcalTPGPhysicsConst.h" +//#include "CondFormats/EcalObjects/interface/EcalTPGSpike.h" +//#include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h" +#include "CondFormats/EcalObjects/interface/EcalTPGStripStatus.h" +#include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeightIdMap.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeightIdMap.h" + +#include "zlib.h" +#include +#include +#include +#include + +// +// class declaration +// + +/** \class EcalEBTrigPrimPhase2ESProducer +\author L. Lutton, N. Marinelli - Univ. of Notre Dame + Description: forPhase II +*/ + +class EcalEBTrigPrimPhase2ESProducer : public edm::ESProducer { +public: + EcalEBTrigPrimPhase2ESProducer(const edm::ParameterSet &); + ~EcalEBTrigPrimPhase2ESProducer() override; + + std::unique_ptr produceLinearizationConst( + const EcalEBPhase2TPGLinearizationConstRcd &); + std::unique_ptr producePedestals(const EcalEBPhase2TPGPedestalsRcd &); + std::unique_ptr produceAmpWeight(const EcalEBPhase2TPGAmplWeightIdMapRcd &); + std::unique_ptr produceTimeWeight(const EcalEBPhase2TPGTimeWeightIdMapRcd &); + std::unique_ptr produceWeightGroup(const EcalTPGWeightGroupRcd &); + std::unique_ptr producePhysicsConst(const EcalTPGPhysicsConstRcd &); + std::unique_ptr produceBadX(const EcalTPGCrystalStatusRcd &); + + // These commented lines are a reminder that in the future we might need to implement something alike + //std::unique_ptr produceLutGroup(const EcalTPGLutGroupRcd &); + //std::uniq//std::unique_ptr produceBadStrip(const EcalTPGStripStatusRcd &); + //std::unique_ptr produceBadTT(const EcalTPGTowerStatusRcd &); + //std::unique_ptr produceSpike(const EcalTPGSpikeRcd &); + +private: + void parseTextFile(); + std::vector getRange(int subdet, int smNb, int towerNbInSm, int stripNbInTower = 0, int xtalNbInStrip = 0); + void parseWeightsFile(); + + // ----------member data --------------------------- + std::string dbFilename_; + // std::string configFilename_; + const edm::FileInPath configFilename_; + bool flagPrint_; + std::map> mapXtal_; + std::map> mapStrip_[2]; + std::map> mapTower_[2]; + std::map> mapWeight_; + std::map> mapTimeWeight_; + std::map> mapXtalToGroup_; + std::map> mapXtalToLin_; + std::map> mapPhys_; + static const int maxSamplesUsed_; + static const int nLinConst_; +}; + +// +// input stream from a gz file +// + +struct GzInputStream { + gzFile gzf; + char buffer[256]; + std::istringstream iss; + bool eof; + GzInputStream(const char *file) : eof(false) { + gzf = gzopen(file, "rb"); + edm::LogInfo("EcalEBTrigPrimPhase2ESProducer") << " New weight file " << file; + if (gzf == Z_NULL) { + eof = true; + edm::LogWarning("EcalEBTrigPrimPhase2ESProducer") << "Database file " << file << " not found!!!"; + } else + readLine(); + } + void readLine() { + char *res = gzgets(gzf, buffer, 256); + eof = (res == Z_NULL); + if (!eof) { + iss.clear(); + iss.str(buffer); + } + } + ~GzInputStream() { gzclose(gzf); } + explicit operator bool() const { return ((eof == true) ? false : !iss.fail()); } +}; + +template +GzInputStream &operator>>(GzInputStream &gis, T &var) { + while ((bool)gis && !(gis.iss >> var)) { + gis.readLine(); + } + return gis; +} + +// +// constructors and destructor +// + +const int EcalEBTrigPrimPhase2ESProducer::maxSamplesUsed_ = 12; +const int EcalEBTrigPrimPhase2ESProducer::nLinConst_ = 8; + +EcalEBTrigPrimPhase2ESProducer::EcalEBTrigPrimPhase2ESProducer(const edm::ParameterSet &iConfig) + : dbFilename_(iConfig.getUntrackedParameter("DatabaseFile", "")), + configFilename_(iConfig.getParameter("WeightTextFile")), + flagPrint_(iConfig.getParameter("WriteInFile")) { + parseWeightsFile(); + + // the following lines are needed to tell the framework what + // data is being produced + setWhatProduced(this, &EcalEBTrigPrimPhase2ESProducer::produceLinearizationConst); + setWhatProduced(this, &EcalEBTrigPrimPhase2ESProducer::producePedestals); + setWhatProduced(this, &EcalEBTrigPrimPhase2ESProducer::produceAmpWeight); + setWhatProduced(this, &EcalEBTrigPrimPhase2ESProducer::produceTimeWeight); + setWhatProduced(this, &EcalEBTrigPrimPhase2ESProducer::produceWeightGroup); + setWhatProduced(this, &EcalEBTrigPrimPhase2ESProducer::produceBadX); + // the following commented lines as a reminder for items which might need to be implemented for Phase2 + //setWhatProduced(this, &EcalEBTrigPrimPhase2ESProducer::producePhysicsConst); + //setWhatProduced(this, &EcalEBTrigPrimPhase2ESProducer::produceBadStrip); + //setWhatProduced(this, &EcalEBTrigPrimPhase2ESProducer::produceBadTT); + //setWhatProduced(this, &EcalEBTrigPrimPhase2ESProducer::produceSpike); +} + +EcalEBTrigPrimPhase2ESProducer::~EcalEBTrigPrimPhase2ESProducer() {} + +// +// member functions +// + +// ------------ method called to produce the data ------------ + +std::unique_ptr EcalEBTrigPrimPhase2ESProducer::producePedestals( + const EcalEBPhase2TPGPedestalsRcd &iRecord) { + auto prod = std::make_unique(); + + std::map>::const_iterator it; + for (it = mapXtalToLin_.begin(); it != mapXtalToLin_.end(); it++) { + EBDetId myEBDetId = EBDetId(it->first); + EcalEBPhase2TPGPedestal ped; + + ped.mean_x10 = (it->second)[0]; + ped.mean_x1 = (it->second)[3]; + prod->insert(std::make_pair(myEBDetId, ped)); + } + + return prod; +} + +std::unique_ptr EcalEBTrigPrimPhase2ESProducer::produceLinearizationConst( + const EcalEBPhase2TPGLinearizationConstRcd &iRecord) { + auto prod = std::make_unique(); + + std::map>::const_iterator it; + for (it = mapXtalToLin_.begin(); it != mapXtalToLin_.end(); it++) { + EcalEBPhase2TPGLinearizationConstant param; + + param.mult_x10 = (it->second)[1]; + param.mult_x1 = (it->second)[5]; + param.shift_x10 = (it->second)[2]; + param.shift_x1 = (it->second)[6]; + param.i2cSub_x10 = (it->second)[3]; + param.i2cSub_x1 = (it->second)[7]; + prod->setValue(it->first, param); + } + + return prod; +} + +std::unique_ptr EcalEBTrigPrimPhase2ESProducer::produceAmpWeight( + const EcalEBPhase2TPGAmplWeightIdMapRcd &iRecord) { + auto prod = std::make_unique(); + + EcalEBPhase2TPGAmplWeights weights; + std::map>::const_iterator it; + for (it = mapWeight_.begin(); it != mapWeight_.end(); it++) { + weights.setValues((it->second)[0], + (it->second)[1], + (it->second)[2], + (it->second)[3], + (it->second)[4], + (it->second)[5], + (it->second)[6], + (it->second)[7], + (it->second)[8], + (it->second)[9], + (it->second)[10], + (it->second)[11]); + prod->setValue(it->first, weights); + } + + return prod; +} + +std::unique_ptr EcalEBTrigPrimPhase2ESProducer::produceTimeWeight( + const EcalEBPhase2TPGTimeWeightIdMapRcd &iRecord) { + auto prod = std::make_unique(); + + EcalEBPhase2TPGTimeWeights weights_time; + std::map>::const_iterator it; + for (it = mapTimeWeight_.begin(); it != mapTimeWeight_.end(); it++) { + weights_time.setValues((it->second)[0], + (it->second)[1], + (it->second)[2], + (it->second)[3], + (it->second)[4], + (it->second)[5], + (it->second)[6], + (it->second)[7], + (it->second)[8], + (it->second)[9], + (it->second)[10], + (it->second)[11]); + prod->setValue(it->first, weights_time); + } + + return prod; +} + +std::unique_ptr EcalEBTrigPrimPhase2ESProducer::produceWeightGroup( + const EcalTPGWeightGroupRcd &iRecord) { + auto prod = std::make_unique(); + + const int NGROUPS = 61200; + + for (int iGroup = 0; iGroup < NGROUPS; iGroup++) { + std::map>::const_iterator it; + for (it = mapXtalToGroup_.begin(); it != mapXtalToGroup_.end(); it++) { + prod->setValue(it->first, it->second[0]); + } + } + + return prod; +} + +std::unique_ptr EcalEBTrigPrimPhase2ESProducer::producePhysicsConst( + const EcalTPGPhysicsConstRcd &iRecord) { + auto prod = std::make_unique(); + // EcalEBTrigPrimPhase2ESProducer::producePhysicsConst Needs updating if we want to keep it + + parseTextFile(); + std::map>::const_iterator it; + for (it = mapPhys_.begin(); it != mapPhys_.end(); it++) { + EcalTPGPhysicsConst::Item item; + item.EtSat = (it->second)[0]; + item.ttf_threshold_Low = (it->second)[1]; + item.ttf_threshold_High = (it->second)[2]; + item.FG_lowThreshold = (it->second)[3]; + item.FG_highThreshold = (it->second)[4]; + item.FG_lowRatio = (it->second)[5]; + item.FG_highRatio = (it->second)[6]; + prod->setValue(it->first, item); + } + + return prod; +} + +std::unique_ptr EcalEBTrigPrimPhase2ESProducer::produceBadX( + const EcalTPGCrystalStatusRcd &iRecord) { + auto prod = std::make_unique(); + + parseTextFile(); + std::map>::const_iterator it; + for (it = mapXtal_.begin(); it != mapXtal_.end(); it++) { + EcalTPGCrystalStatusCode badXValue; + badXValue.setStatusCode(0); + prod->setValue(it->first, badXValue); + } + return prod; +} + +void EcalEBTrigPrimPhase2ESProducer::parseWeightsFile() { + uint32_t id; + std::string dataCard; + std::vector param; + + int data; + std::string filename = configFilename_.fullPath(); + ; + std::string finalFileName; + size_t slash = filename.find('/'); + if (slash != 0) { + edm::FileInPath fileInPath(filename); + finalFileName = fileInPath.fullPath(); + } else { + finalFileName = filename; + edm::LogWarning("EcalEBTPGESProducer") + << "Couldnt find database file via fileinpath trying with pathname directly!!"; + } + + GzInputStream gis(finalFileName.c_str()); + while (gis >> dataCard) { + if (dataCard == "WEIGHTAMP") { + gis >> std::dec >> id; + + if (flagPrint_) { + std::cout << dataCard << " " << std::dec << id << std::endl; + } + + param.clear(); + + std::string st6; + for (int i = 0; i < maxSamplesUsed_; i++) { + gis >> std::hex >> data; + param.push_back(data); + /// debug + + if (flagPrint_) { + std::ostringstream oss; + oss << std::hex << data; + std::string result4 = oss.str(); + + st6.append("0x"); + st6.append(result4); + st6.append(" "); + } + } + + // debug + if (flagPrint_) { + std::cout << st6 << std::endl; + std::cout << std::endl; + } + + // std::cout << " WEIGHTAMP id " << id << std::endl; + mapWeight_[id] = param; + } + + if (dataCard == "WEIGHTTIME") { + gis >> std::dec >> id; + + if (flagPrint_) { + std::cout << dataCard << " " << std::dec << id << std::endl; + } + + param.clear(); + + std::string st6; + for (int i = 0; i < maxSamplesUsed_; i++) { + gis >> std::hex >> data; + //std::cout << " Parse time weight filling data " << data; + param.push_back(data); + /// debug + + if (flagPrint_) { + std::ostringstream oss; + oss << std::hex << data; + std::string result4 = oss.str(); + + st6.append("0x"); + st6.append(result4); + st6.append(" "); + } + } + + // debug + if (flagPrint_) { + std::cout << st6 << std::endl; + std::cout << std::endl; + } + mapTimeWeight_[id] = param; + } + + if (dataCard == "CRYSTAL") { + gis >> std::dec >> id; + + if (flagPrint_) { + std::cout << dataCard << " " << std::dec << id << std::endl; + } + + param.clear(); + std::string st6; + gis >> std::dec >> data; + param.push_back(data); + + if (flagPrint_) { + std::ostringstream oss; + oss << std::dec << data; + std::string result4 = oss.str(); + st6.append(result4); + st6.append(" "); + std::cout << st6 << std::endl; + std::cout << std::endl; + } + mapXtalToGroup_[id] = param; + } + + if (dataCard == "LINCONST") { + gis >> std::dec >> id; + + if (flagPrint_) { + std::cout << dataCard << " " << std::dec << id << std::endl; + } + + param.clear(); + std::string st6; + std::string st7; + + for (int i = 0; i < nLinConst_; i++) { + gis >> std::hex >> data; + param.push_back(data); + + if (flagPrint_) { + if (i < 4) { + std::ostringstream oss; + oss << std::hex << data; + std::string result6 = oss.str(); + st6.append("0x"); + st6.append(result6); + if (i != 3) + st6.append(" "); + } else if (i < 8) { + std::ostringstream oss; + oss << std::hex << data; + std::string result7 = oss.str(); + st7.append("0x"); + st7.append(result7); + if (i != 7) + st7.append(" "); + } + } + } + if (flagPrint_) { + std::cout << st6 << std::endl; + std::cout << st7 << std::endl; + } + mapXtalToLin_[id] = param; + } + } +} + +void EcalEBTrigPrimPhase2ESProducer::parseTextFile() { + if (!mapXtal_.empty()) + return; // just parse the file once! + + uint32_t id; + std::string dataCard; + std::string line; + std::ifstream infile; + std::vector param; + std::vector paramF; + int NBstripparams[2] = {4, 4}; + unsigned int data; + + std::string bufString; + std::string iString; + std::string fString; + std::string filename = "SimCalorimetry/EcalTrigPrimProducers/data/" + dbFilename_; + std::string finalFileName; + size_t slash = dbFilename_.find('/'); + if (slash != 0) { + edm::FileInPath fileInPath(filename); + finalFileName = fileInPath.fullPath(); + } else { + finalFileName = dbFilename_; + edm::LogWarning("EcalTPG") << "Couldnt find database file via fileinpath, " + "trying with pathname directly!!"; + } + + int k = 0; + + GzInputStream gis(finalFileName.c_str()); + while (gis >> dataCard) { + if (dataCard == "CRYSTAL") { + gis >> std::dec >> id; + + std::string st3; + std::string st4; + std::string st5; + + if (flagPrint_) { + // Print this comment only one time + if (k == 0) + std::cout << "COMMENT ====== barrel crystals ====== " << std::endl; + + if (k == 61200) + std::cout << "COMMENT ====== endcap crystals ====== " << std::endl; + + k = k + 1; + + std::cout << dataCard << " " << std::dec << id << std::endl; + } + + param.clear(); + for (int i = 0; i < 9; i++) { + gis >> std::hex >> data; + param.push_back(data); + + if (flagPrint_) { + if (i < 3) { + std::ostringstream oss; + oss << std::hex << data; + std::string result1 = oss.str(); + + st3.append("0x"); + st3.append(result1); + if (i != 2) + st3.append(" "); + + } else if (i > 2 && i < 6) { + std::ostringstream oss; + oss << std::hex << data; + std::string result2 = oss.str(); + + st4.append("0x"); + st4.append(result2); + if (i != 5) + st4.append(" "); + } else if (i > 5 && i < 9) { + std::ostringstream oss; + oss << std::hex << data; + std::string result3 = oss.str(); + + st5.append("0x"); + st5.append(result3); + if (i != 8) + st5.append(" "); + } + } + + } // end for + + if (flagPrint_) { + std::cout << " " << st3 << std::endl; + std::cout << " " << st4 << std::endl; + std::cout << " " << st5 << std::endl; + } + + mapXtal_[id] = param; + } + + if (dataCard == "STRIP_EB") { + gis >> std::dec >> id; + + std::string st1; + + if (flagPrint_) + std::cout << dataCard << " " << std::dec << id << std::endl; + + param.clear(); + for (int i = 0; i < NBstripparams[0]; i++) { + gis >> std::hex >> data; + param.push_back(data); + + if (flagPrint_) { + if (i == 0) { + std::cout << "0x" << std::hex << data << std::endl; + } else if (i == 1) { + std::cout << "" << std::hex << data << std::endl; + } else if (i > 1) { + std::ostringstream oss; + if (i == 2) { + oss << "0x" << std::hex << data; + std::string result4 = oss.str(); + st1.append(result4); + } else if (i == 3) { + std::ostringstream oss; + oss << " 0x" << std::hex << data; + std::string result5 = oss.str(); + + st1.append(result5); + std::cout << "" << st1 << std::endl; + } + } + } + } + + mapStrip_[0][id] = param; + } + + if (dataCard == "STRIP_EE") { + gis >> std::dec >> id; + + std::string st6; + + if (flagPrint_) { + std::cout << dataCard << " " << std::dec << id << std::endl; + } + + param.clear(); + for (int i = 0; i < NBstripparams[1]; i++) { + gis >> std::hex >> data; + param.push_back(data); + + if (flagPrint_) { + if (i == 0) { + std::cout << "0x" << std::hex << data << std::endl; + } else if (i == 1) { + std::cout << " " << std::hex << data << std::endl; + } else if (i > 1) { + std::ostringstream oss; + if (i == 2) { + oss << "0x" << std::hex << data; + std::string result4 = oss.str(); + st6.append(result4); + } else if (i == 3) { + std::ostringstream oss; + oss << " 0x" << std::hex << data; + std::string result5 = oss.str(); + + st6.append(result5); + std::cout << "" << st6 << std::endl; + } + } + } + } + + mapStrip_[1][id] = param; + } + + if (dataCard == "TOWER_EE") { + gis >> std::dec >> id; + + if (flagPrint_) + std::cout << dataCard << " " << std::dec << id << std::endl; + + param.clear(); + for (int i = 0; i < 2; i++) { + gis >> std::hex >> data; + param.push_back(data); + + if (flagPrint_) { + if (i == 1) { + std::cout << "0x" << std::dec << data << std::endl; + } else { + std::cout << " " << std::dec << data << std::endl; + } + } + } + + mapTower_[1][id] = param; + } + + if (dataCard == "TOWER_EB") { + gis >> std::dec >> id; + + if (flagPrint_) + std::cout << dataCard << " " << std::dec << id << std::endl; + + param.clear(); + for (int i = 0; i < 3; i++) { + gis >> std::dec >> data; + + if (flagPrint_) { + std::cout << " " << std::dec << data << std::endl; + } + + param.push_back(data); + } + + mapTower_[0][id] = param; + } + } +} + +/// This method is not used at all, however is a reminder that something alike will probably be needed once the mapping EB to BCPs will be in place +std::vector EcalEBTrigPrimPhase2ESProducer::getRange( + int subdet, int tccNb, int towerNbInTcc, int stripNbInTower, int xtalNbInStrip) { + std::vector range; + if (subdet == 0) { + // Barrel + range.push_back(37); // stccNbMin + range.push_back(73); // tccNbMax + range.push_back(1); // towerNbMin + range.push_back(69); // towerNbMax + range.push_back(1); // stripNbMin + range.push_back(6); // stripNbMax + range.push_back(1); // xtalNbMin + range.push_back(6); // xtalNbMax + } + + if (tccNb > 0) { + range[0] = tccNb; + range[1] = tccNb + 1; + } + if (towerNbInTcc > 0) { + range[2] = towerNbInTcc; + range[3] = towerNbInTcc + 1; + } + if (stripNbInTower > 0) { + range[4] = stripNbInTower; + range[5] = stripNbInTower + 1; + } + if (xtalNbInStrip > 0) { + range[6] = xtalNbInStrip; + range[7] = xtalNbInStrip + 1; + } + + return range; +} + +DEFINE_FWK_EVENTSETUP_MODULE(EcalEBTrigPrimPhase2ESProducer); diff --git a/SimCalorimetry/EcalEBTrigPrimProducers/plugins/EcalEBTrigPrimPhase2Producer.cc b/SimCalorimetry/EcalEBTrigPrimProducers/plugins/EcalEBTrigPrimPhase2Producer.cc new file mode 100644 index 0000000000000..3db2b7efd790a --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimProducers/plugins/EcalEBTrigPrimPhase2Producer.cc @@ -0,0 +1,244 @@ +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Utilities/interface/EDGetToken.h" +#include "FWCore/Utilities/interface/ESGetToken.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +// +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Provenance/interface/ProductID.h" +#include "DataFormats/Provenance/interface/ParameterSetID.h" +#include "DataFormats/Provenance/interface/Provenance.h" +#include "DataFormats/EcalDigi/interface/EcalDigiCollections.h" +#include "CondFormats/EcalObjects/interface/EcalLiteDTUPedestals.h" +#include "CondFormats/DataRecord/interface/EcalLiteDTUPedestalsRcd.h" + +#include "CondFormats/DataRecord/interface/EcalTPGCrystalStatusRcd.h" +#include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h" +#include "CondFormats/DataRecord/interface/EcalEBPhase2TPGPedestalsRcd.h" +#include "CondFormats/DataRecord/interface/EcalEBPhase2TPGLinearizationConstRcd.h" +#include "CondFormats/DataRecord/interface/EcalEBPhase2TPGAmplWeightIdMapRcd.h" +#include "CondFormats/DataRecord/interface/EcalEBPhase2TPGTimeWeightIdMapRcd.h" +#include "CondFormats/DataRecord/interface/EcalTPGWeightGroupRcd.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeightIdMap.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeightIdMap.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGLinearizationConst.h" +#include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGPedestals.h" +#include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h" +#include "CondFormats/DataRecord/interface/EcalTPGTowerStatusRcd.h" +#include "CondFormats/DataRecord/interface/EcalTPGSpikeRcd.h" +#include "CondFormats/EcalObjects/interface/EcalTPGSpike.h" +#include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h" + +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" + +// We keep these lines for future posssible necessary additions +//#include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h" +//#include "CondFormats/DataRecord/interface/EcalTPGStripStatusRcd.h" +//#include "CondFormats/EcalObjects/interface/EcalTPGStripStatus.h" +#include "SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TrigPrimAlgo.h" +#include + +// Class declaration +/** \class EcalEBTrigPrimPhase2Producer \author L. Lutton, N. Marinelli - Univ. of Notre Dame Description: forPhase II It consumes the new Phase2 digis based on the new EB electronics and plugs in the main steering algo for TP emulation It produces the EcalEBPhase2TrigPrimDigiCollection */ + +class EcalEBPhase2TrigPrimAlgo; + +class EcalEBTrigPrimPhase2Producer : public edm::stream::EDProducer<> { +public: + explicit EcalEBTrigPrimPhase2Producer(const edm::ParameterSet& conf); + + ~EcalEBTrigPrimPhase2Producer() override; + + void beginRun(const edm::Run& run, const edm::EventSetup& es) override; + void endRun(const edm::Run&, const edm::EventSetup&) override; + void produce(edm::Event& e, const edm::EventSetup& c) override; + static void fillDescriptions(edm::ConfigurationDescriptions&); + +private: + std::unique_ptr algo_; + bool debug_; + bool famos_; + int nEvent_; + edm::EDGetTokenT tokenEBdigi_; + edm::ESGetToken + theEcalEBPhase2TPGLinearization_Token_; + edm::ESGetToken theEcalEBPhase2TPGPedestals_Token_; + + edm::ESGetToken theEcalTPGPedestals_Token_; + + edm::ESGetToken theEcalTPGCrystalStatus_Token_; + edm::ESGetToken theEcalEBTPGAmplWeightIdMap_Token_; + edm::ESGetToken theEcalEBTPGTimeWeightIdMap_Token_; + + edm::ESGetToken theEcalTPGWeightGroup_Token_; + + edm::ESGetToken theEcalTPGTowerStatus_Token_; + edm::ESGetToken theEcalTPGSpike_Token_; + + edm::ESGetToken eTTmapToken_; + edm::ESGetToken theGeometryToken_; + + int binOfMaximum_; + bool fillBinOfMaximumFromHistory_; + + unsigned long long getRecords(edm::EventSetup const& setup); + unsigned long long cacheID_; +}; + +EcalEBTrigPrimPhase2Producer::EcalEBTrigPrimPhase2Producer(const edm::ParameterSet& iConfig) + : debug_(iConfig.getParameter("Debug")), + famos_(iConfig.getParameter("Famos")), + binOfMaximum_(iConfig.getParameter("binOfMaximum")) { + tokenEBdigi_ = consumes(iConfig.getParameter("barrelEcalDigis")); + + eTTmapToken_ = esConsumes(); + theGeometryToken_ = esConsumes(); + + theEcalTPGPedestals_Token_ = + esConsumes(); + theEcalEBPhase2TPGPedestals_Token_ = + esConsumes(); + + theEcalTPGCrystalStatus_Token_ = + esConsumes(); + theEcalEBPhase2TPGLinearization_Token_ = + esConsumes(); + theEcalEBTPGAmplWeightIdMap_Token_ = + esConsumes(); + theEcalEBTPGTimeWeightIdMap_Token_ = + esConsumes(); + theEcalTPGWeightGroup_Token_ = esConsumes(); + + //register your products + produces(); +} + +void EcalEBTrigPrimPhase2Producer::beginRun(edm::Run const& run, edm::EventSetup const& setup) { + auto const& theGeometry = setup.getData(theGeometryToken_); + auto const& eTTmap = setup.getData(eTTmapToken_); + + algo_ = std::make_unique(&eTTmap, &theGeometry, binOfMaximum_, debug_); + + // get a first version of the records + cacheID_ = this->getRecords(setup); + + nEvent_ = 0; +} + +void EcalEBTrigPrimPhase2Producer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("Debug", false); + desc.add("Famos", false); + desc.add("BinOfMaximum", 6); // this needs to be at the same value used for the Phase2 LiteDTU digis ! + desc.add("barrelEcalDigis", edm::InputTag("simEcalUnsuppressedDigis")); +} + +unsigned long long EcalEBTrigPrimPhase2Producer::getRecords(edm::EventSetup const& setup) { + // get parameter records for xtals + auto theEcalEBPhase2TPGLinearization_handle = setup.getHandle(theEcalEBPhase2TPGLinearization_Token_); + const EcalEBPhase2TPGLinearizationConst* ecaltpLin = theEcalEBPhase2TPGLinearization_handle.product(); + // + edm::ESHandle theEcalTPGPedestals_handle = setup.getHandle(theEcalTPGPedestals_Token_); + const EcalLiteDTUPedestalsMap* ecaltpPed = theEcalTPGPedestals_handle.product(); + // + // auto theEcalEBPhase2TPGPedestals_handle = setup.getHandle(theEcalEBPhase2TPGPedestals_Token_); + //const EcalEBPhase2TPGPedestalsMap* ebTPPedestals = theEcalEBPhase2TPGPedestals_handle.product(); + // + edm::ESHandle theEcalTPGCrystalStatus_handle = setup.getHandle(theEcalTPGCrystalStatus_Token_); + const EcalTPGCrystalStatus* ecaltpgBadX = theEcalTPGCrystalStatus_handle.product(); + // + edm::ESHandle theEcalEBTPGAmplWeightIdMap_handle = + setup.getHandle(theEcalEBTPGAmplWeightIdMap_Token_); + const EcalEBPhase2TPGAmplWeightIdMap* ecaltpgAmplWeightMap = theEcalEBTPGAmplWeightIdMap_handle.product(); + // + edm::ESHandle theEcalEBTPGTimeWeightIdMap_handle = + setup.getHandle(theEcalEBTPGTimeWeightIdMap_Token_); + const EcalEBPhase2TPGTimeWeightIdMap* ecaltpgTimeWeightMap = theEcalEBTPGTimeWeightIdMap_handle.product(); + // + edm::ESHandle theEcalTPGWeightGroup_handle = setup.getHandle(theEcalTPGWeightGroup_Token_); + const EcalTPGWeightGroup* ecaltpgWeightGroup = theEcalTPGWeightGroup_handle.product(); + // These commented out lines are for reminder for possible needed implementations + //edm::ESHandle theEcalTPGTowerStatus_handle = setup.getHandle(theEcalTPGTowerStatus_Token_); + //const EcalTPGTowerStatus* ecaltpgBadTT = theEcalTPGTowerStatus_handle.product(); + // + //edm::ESHandle theEcalTPGSpike_handle = setup.getHandle(theEcalTPGSpike_Token_); + //const EcalTPGSpike* ecaltpgSpike = theEcalTPGSpike_handle.product(); + + //////////////// + algo_->setPointers(ecaltpPed, ecaltpLin, ecaltpgBadX, ecaltpgAmplWeightMap, ecaltpgTimeWeightMap, ecaltpgWeightGroup); + + return setup.get().cacheIdentifier(); + // return setup.get().cacheIdentifier(); +} + +void EcalEBTrigPrimPhase2Producer::endRun(edm::Run const& run, edm::EventSetup const& setup) { algo_.reset(); } + +EcalEBTrigPrimPhase2Producer::~EcalEBTrigPrimPhase2Producer() {} + +// ------------ method called to produce the data ------------ +void EcalEBTrigPrimPhase2Producer::produce(edm::Event& e, const edm::EventSetup& iSetup) { + nEvent_++; + + // get input collections + edm::Handle barrelDigiHandle; + + if (!e.getByToken(tokenEBdigi_, barrelDigiHandle)) { + edm::EDConsumerBase::Labels labels; + labelsForToken(tokenEBdigi_, labels); + edm::LogWarning("EcalTPG") << " Couldnt find Barrel digis " << labels.module << " and label " + << labels.productInstance << "!!!"; + } + const auto* ebdigi = barrelDigiHandle.product(); + + if (debug_) + LogDebug("EcalEBTrigPrimPhase2Producer") + << " EcalTPG" + << " =================> Treating event " << nEvent_ << ", Number of EB digis " + << barrelDigiHandle.product()->size() << std::endl; + + auto pOut = std::make_unique(); + + // invoke algorithm + algo_->run(ebdigi, *pOut); + + if (debug_) { + LogDebug("EcalEBTrigPrimPhase2Producer") + << "produce" + << " For Barrel " << pOut->size() << " TP Digis were produced" << std::endl; + } + + // debug prints if TP > 0. The number of TP with Et>0 is also used later for a LogInfo + int nonZeroTP = 0; + int nXstal = 0; + for (unsigned int i = 0; i < pOut->size(); ++i) { + nXstal++; + for (int isam = 0; isam < (*pOut)[i].size(); ++isam) { + if ((*pOut)[i][isam].encodedEt() > 0) { + nonZeroTP++; + if (debug_) { + LogDebug("EcalEBTrigPrimPhase2Producer") + << " For xStal n " << nXstal << " xTsal Id " << (((*pOut)[i])).id() << ", TP is " << (*pOut)[i] + << " (*pOut)[i][isam].raw() " << (*pOut)[i][isam].raw() << " (*pOut)[i][isam].encodedEt() " + << (*pOut)[i][isam].encodedEt() << " (*pOut)[i][isam].time() " << (*pOut)[i][isam].time() << std::endl; + } + } + } + } + + edm::LogInfo("EcalEBTrigPrimPhase2Producer") + << "EcalTPG" + << "\n =================> For Barrel , " << pOut->size() << " TP Digis were produced (including zero ones)" + << " Non zero primitives were " << nonZeroTP << std::endl; + + // put result into the Event + e.put(std::move(pOut)); +} + +DEFINE_FWK_MODULE(EcalEBTrigPrimPhase2Producer); diff --git a/SimCalorimetry/EcalEBTrigPrimProducers/plugins/SealModules.cc b/SimCalorimetry/EcalEBTrigPrimProducers/plugins/SealModules.cc index e959e18ebaa06..f439ac86bd7cc 100644 --- a/SimCalorimetry/EcalEBTrigPrimProducers/plugins/SealModules.cc +++ b/SimCalorimetry/EcalEBTrigPrimProducers/plugins/SealModules.cc @@ -1,7 +1,4 @@ #include "FWCore/Framework/interface/MakerMacros.h" #include "EcalEBTrigPrimProducer.h" -#include "EcalEBTrigPrimAnalyzer.h" - DEFINE_FWK_MODULE(EcalEBTrigPrimProducer); -DEFINE_FWK_MODULE(EcalEBTrigPrimAnalyzer); diff --git a/SimCalorimetry/EcalEBTrigPrimProducers/python/ecalEBTriggerPrimitivePhase2Digis_cfi.py b/SimCalorimetry/EcalEBTrigPrimProducers/python/ecalEBTriggerPrimitivePhase2Digis_cfi.py new file mode 100644 index 0000000000000..fd567eac36e9c --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimProducers/python/ecalEBTriggerPrimitivePhase2Digis_cfi.py @@ -0,0 +1,17 @@ +import FWCore.ParameterSet.Config as cms + +# +# attention: default is changed to work on unsuppressed digis!! ############## +# + +simEcalEBTriggerPrimitivePhase2Digis = cms.EDProducer("EcalEBTrigPrimPhase2Producer", + barrelEcalDigis = cms.InputTag("simEcalUnsuppressedDigis"), + binOfMaximum = cms.int32(6), + Famos = cms.bool(False), + TcpOutput = cms.bool(False), + Debug = cms.bool(False) +) + + +from Configuration.Eras.Modifier_phase2_ecalTP_devel_cff import phase2_ecalTP_devel +phase2_ecalTP_devel.toModify( simEcalEBTriggerPrimitivePhase2Digis) diff --git a/SimCalorimetry/EcalEBTrigPrimProducers/python/ecalEBTriggerPrimitivePhase2ESProducer_cfi.py b/SimCalorimetry/EcalEBTrigPrimProducers/python/ecalEBTriggerPrimitivePhase2ESProducer_cfi.py new file mode 100644 index 0000000000000..ab45cd4f266eb --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimProducers/python/ecalEBTriggerPrimitivePhase2ESProducer_cfi.py @@ -0,0 +1,73 @@ +import os +import FWCore.ParameterSet.Config as cms + +# esmodule creating records + corresponding empty essource +EcalEBTrigPrimPhase2ESProducer = cms.ESProducer("EcalEBTrigPrimPhase2ESProducer", + DatabaseFile = cms.untracked.string('TPG_beamv5_MC_startup.txt.gz'), + WeightTextFile = cms.FileInPath('SimCalorimetry/EcalEBTrigPrimProducers/data/AmpTimeOnPeakXtalWeightsCMSSWPulse_8samples_peakOnSix_WithAndyFixes.txt.gz'), + WriteInFile = cms.bool(False) +) + +tpparams = cms.ESSource("EmptyESSource", + recordName = cms.string('EcalEBPhase2TPGLinearizationConstRcd'), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(1) +) + +tpparams2 = cms.ESSource("EmptyESSource", + recordName = cms.string('EcalEBPhase2TPGPedestalsRcd'), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(1) +) + + +tpparams4 = cms.ESSource("EmptyESSource", + recordName = cms.string('EcalEBPhase2TPGAmplWeightIdMapRcd'), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(1) +) + +tpparams17 = cms.ESSource("EmptyESSource", + recordName = cms.string('EcalEBPhase2TPGTimeWeightIdMapRcd'), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(1) +) + + +tpparams5 = cms.ESSource("EmptyESSource", + recordName = cms.string('EcalTPGWeightGroupRcd'), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(1) +) + + +tpparams12 = cms.ESSource("EmptyESSource", + recordName = cms.string('EcalTPGPhysicsConstRcd'), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(1) +) + +tpparams13 = cms.ESSource("EmptyESSource", + recordName = cms.string('EcalTPGCrystalStatusRcd'), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(1) +) + +tpparams14 = cms.ESSource("EmptyESSource", + recordName = cms.string('EcalTPGTowerStatusRcd'), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(1) +) + +tpparams15 = cms.ESSource("EmptyESSource", + recordName = cms.string('EcalTPGSpikeRcd'), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(1) +) + +tpparams16 = cms.ESSource("EmptyESSource", + recordName = cms.string('EcalTPGStripStatusRcd'), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(1) +) + diff --git a/SimCalorimetry/EcalEBTrigPrimProducers/test/testPhase2_13_1_0_pre3.py b/SimCalorimetry/EcalEBTrigPrimProducers/test/testPhase2_13_1_0_pre3.py new file mode 100644 index 0000000000000..5d15178047eb2 --- /dev/null +++ b/SimCalorimetry/EcalEBTrigPrimProducers/test/testPhase2_13_1_0_pre3.py @@ -0,0 +1,164 @@ +# Auto generated configuration file +# using: +# Revision: 1.19 +# Source: /local/reps/CMSSW/CMSSW/Configuration/Applications/python/ConfigBuilder.py,v +# with command line options: TTbar_14TeV_TuneCP5_cfi --conditions auto:phase2_realistic_T15 -n 1 --era Phase2C10 --eventcontent FEVTDEBUG --relval +#9000,100 -s GEN,SIM,DIGI --datatier GEN-SIM-DIGI --beamspot HLLHC14TeV --geometry Extended2026D60 --fileout file:step1_UpToDigi.root + + +import FWCore.ParameterSet.Config as cms +from Configuration.Eras.Era_Phase2C17I13M9_cff import Phase2C17I13M9 +from Configuration.Eras.Modifier_phase2_ecal_devel_cff import phase2_ecal_devel +from Configuration.Eras.Modifier_phase2_ecalTP_devel_cff import phase2_ecalTP_devel + +process = cms.Process('DIGI',Phase2C17I13M9,phase2_ecal_devel,phase2_ecalTP_devel) + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('SimGeneral.HepPDTESSource.pythiapdt_cfi') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.EventContent.EventContent_cff') +process.load('SimGeneral.MixingModule.mixNoPU_cfi') +process.load('Configuration.Geometry.GeometryExtended2026D88Reco_cff') +process.load('Configuration.Geometry.GeometryExtended2026D88_cff') +process.load('Configuration.StandardSequences.MagneticField_cff') +process.load('Configuration.StandardSequences.Generator_cff') +process.load('IOMC.EventVertexGenerators.VtxSmearedHLLHC14TeV_cfi') +process.load('GeneratorInterface.Core.genFilterSummary_cff') +process.load('Configuration.StandardSequences.SimIdeal_cff') +process.load('Configuration.StandardSequences.Digi_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(1), + output = cms.optional.untracked.allowed(cms.int32,cms.PSet) +) + + +process.MessageLogger = cms.Service("MessageLogger", + destinations = cms.untracked.vstring('messages'), + messages = cms.untracked.PSet(threshold = cms.untracked.string('DEBUG')), + debugModules = cms.untracked.vstring('*') + + +) + + + +# Input source +process.source = cms.Source("EmptySource") + +process.options = cms.untracked.PSet( + FailPath = cms.untracked.vstring(), + IgnoreCompletely = cms.untracked.vstring(), + Rethrow = cms.untracked.vstring(), + SkipEvent = cms.untracked.vstring(), + allowUnscheduled = cms.obsolete.untracked.bool, + canDeleteEarly = cms.untracked.vstring(), + emptyRunLumiMode = cms.obsolete.untracked.string, + eventSetup = cms.untracked.PSet( + forceNumberOfConcurrentIOVs = cms.untracked.PSet( + + ), + numberOfConcurrentIOVs = cms.untracked.uint32(1) + ), + fileMode = cms.untracked.string('FULLMERGE'), + forceEventSetupCacheClearOnNewRun = cms.untracked.bool(False), + makeTriggerResults = cms.obsolete.untracked.bool, + numberOfConcurrentLuminosityBlocks = cms.untracked.uint32(1), + numberOfConcurrentRuns = cms.untracked.uint32(1), + numberOfStreams = cms.untracked.uint32(0), + numberOfThreads = cms.untracked.uint32(1), + printDependencies = cms.untracked.bool(False), + sizeOfStackForThreadsInKB = cms.optional.untracked.uint32, + throwIfIllegalParameter = cms.untracked.bool(True), + wantSummary = cms.untracked.bool(False) +) + + + +# Production Info +process.configurationMetadata = cms.untracked.PSet( + annotation = cms.untracked.string('TTbar_14TeV_TuneCP5_cfi nevts:1'), + name = cms.untracked.string('Applications'), + version = cms.untracked.string('$Revision: 1.19 $') +) + +# Output definition + +process.FEVTDEBUGoutput = cms.OutputModule("PoolOutputModule", + SelectEvents = cms.untracked.PSet( + SelectEvents = cms.vstring('generation_step') + ), + dataset = cms.untracked.PSet( + dataTier = cms.untracked.string('GEN-SIM-DIGI'), + filterName = cms.untracked.string('') + ), + fileName = cms.untracked.string('file:/tmp/nancy/testGamma_Nancy.root'), + outputCommands = process.FEVTDEBUGEventContent.outputCommands, + splitLevel = cms.untracked.int32(0) +) + +# Additional output definition + +# Other statements +process.genstepfilter.triggerConditions=cms.vstring("generation_step") +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic_T21', '') + +process.GlobalTag.toGet = cms.VPSet( + cms.PSet(record = cms.string("EcalSimPulseShapeRcd"), + tag = cms.string("EcalSimPulseShapePhaseII"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS") + ) +) + + + +process.generator = cms.EDFilter("Pythia8PtGun", + PGunParameters = cms.PSet( + AddAntiParticle = cms.bool(True), + MaxEta = cms.double(1.4), + MaxPhi = cms.double(3.14159265359), + MaxPt = cms.double(1000.01), + MinEta = cms.double(-1.4), + MinPhi = cms.double(-3.14159265359), + MinPt = cms.double(0.5), + ParticleID = cms.vint32(11) + ), + PythiaParameters = cms.PSet( + parameterSets = cms.vstring() + ), + Verbosity = cms.untracked.int32(0), + firstRun = cms.untracked.uint32(1), + psethack = cms.string('single electron flat Pt 0.5 to 100 GeV ') +) + +process.ProductionFilterSequence = cms.Sequence(process.generator) + +# Path and EndPath definitions +process.generation_step = cms.Path(process.pgen) +process.simulation_step = cms.Path(process.psim) +process.digitisation_step = cms.Path(process.pdigi) +process.genfiltersummary_step = cms.EndPath(process.genFilterSummary) +process.endjob_step = cms.EndPath(process.endOfProcess) +process.FEVTDEBUGoutput_step = cms.EndPath(process.FEVTDEBUGoutput) + +# Schedule definition +process.schedule = cms.Schedule(process.generation_step,process.genfiltersummary_step,process.simulation_step,process.digitisation_step,process.endjob_step,process.FEVTDEBUGoutput_step) +from PhysicsTools.PatAlgos.tools.helpers import associatePatAlgosToolsTask +associatePatAlgosToolsTask(process) +# filter all path with the production filter sequence +for path in process.paths: + getattr(process,path).insert(0, process.ProductionFilterSequence) + + + +# Customisation from command line + +# Add early deletion of temporary data products to reduce peak memory need +from Configuration.StandardSequences.earlyDeleteSettings_cff import customiseEarlyDelete +process = customiseEarlyDelete(process) +# End adding early deletion +