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