50 void fillFMat(std::vector<unsigned int> clockSampleSet,
52 std::vector<float> sampleSet,
53 std::vector<float> sampleDotSet,
56 void getGMatrix(TMatrix FMat,
float scaleMatrixBy, TMatrix& GMat);
57 void getPulseSampleSet(TGraph pulseGraph,
float phaseShift, std::vector<float>& sampleSet);
89 inFile_(pSet.getParameter<
edm::FileInPath>(
"inputFile")),
90 outFile_(pSet.getUntrackedParameter<
std::
string>(
"outputFile")),
91 nSamplesToUse_(pSet.getParameter<unsigned
int>(
"nSamplesToUse")),
92 useBXPlusOne_(pSet.getParameter<
bool>(
"useBXPlusOne")),
93 phaseShift_(pSet.getParameter<double>(
"phaseShift")),
94 nWeightGroups_(pSet.getParameter<unsigned
int>(
"nWeightGroups")),
96 et_sat_(pSet.getParameter<double>(
"Et_sat")),
97 xtal_LSB_(pSet.getParameter<double>(
"xtal_LSB")),
98 binOfMaximum_(pSet.getParameter<unsigned
int>(
"binOfMaximum"))
111 <<
" Value for binOfMaximum " <<
binOfMaximum_ <<
" is wrong, The default binOfMaximum=6 will be used";
115 <<
" Value for nSamplesToUse " <<
nSamplesToUse_ <<
" is wrong, The default nSamplesToUse=8 will be used";
126 desc.add<
unsigned int>(
"nSamplesToUse", 8);
127 desc.add<
bool>(
"useBXPlusOne",
false);
128 desc.add<
double>(
"phaseShift", 2.581);
129 desc.add<
unsigned int>(
"nWeightGroups", 61200);
130 desc.add<
double>(
"Et_sat", 1998.36);
131 desc.add<
double>(
"xtal_LSB", 0.0488);
132 desc.add<
unsigned int>(
"binOfMaximum", 6);
133 descriptions.
add(
"ecalEBPhase2TPParamProducerDefault",
desc);
145 const char* tmpStringOut;
157 std::stringstream toCompressStream(
"");
159 toCompressStream <<
" WEIGHTAMP " <<
dec << iGr << std::endl;
160 for (
long unsigned int i = 0;
i < ampWeights[iGr].size();
i++) {
161 if (ampWeights[iGr][
i] < 0)
162 toCompressStream <<
"-0x" << std::hex <<
abs(ampWeights[iGr][
i]) <<
" ";
164 toCompressStream <<
"0x" << std::hex << ampWeights[iGr][
i] <<
" ";
166 toCompressStream <<
"\n";
168 toCompressStream <<
"\n";
169 tmpStringConv = toCompressStream.str();
170 tmpStringOut = tmpStringConv.c_str();
171 gzwrite(
out_file_, tmpStringOut, std::strlen(tmpStringOut));
175 toCompressStream <<
"WEIGHTTIME " <<
dec << iGr << std::endl;
176 for (
long unsigned int i = 0;
i < timeWeights[iGr].size();
i++) {
177 if (timeWeights[iGr][
i] < 0)
178 toCompressStream <<
"-0x" << std::hex <<
abs(timeWeights[iGr][
i]) <<
" ";
180 toCompressStream <<
"0x" << std::hex << timeWeights[iGr][
i] <<
" ";
182 toCompressStream <<
"\n";
185 toCompressStream <<
"\n";
186 tmpStringConv = toCompressStream.str();
187 tmpStringOut = tmpStringConv.c_str();
188 gzwrite(
out_file_, tmpStringOut, std::strlen(tmpStringOut));
193 std::map<int, int> mapXtalToGroup;
196 for (
const auto&
it : ebCells) {
198 std::pair<int, int> xTalToGroup(
id.
rawId(), iGroup);
199 mapXtalToGroup.insert(xTalToGroup);
205 for (std::map<int, int>::const_iterator
it = mapXtalToGroup.begin();
it != mapXtalToGroup.end();
it++) {
206 toCompressStream <<
"CRYSTAL " <<
dec <<
it->first << std::endl;
207 toCompressStream <<
it->second << std::endl;
209 tmpStringConv = toCompressStream.str();
210 tmpStringOut = tmpStringConv.c_str();
211 gzwrite(
out_file_, tmpStringOut, std::strlen(tmpStringOut));
216 for (
const auto&
it : ebCells) {
218 toCompressStream <<
"LINCONST " <<
dec <<
id.rawId() << std::endl;
219 double theta = theBarrelGeometry->getGeometry(
id)->getPosition().theta();
222 if (itped != theEcalTPPedestals->end()) {
226 edm::LogError(
"EcalEBPhase2TPParamProducer") <<
" could not find EcalLiteDTUPedestal entry for " <<
id;
231 double calibCoeff = 1.;
237 <<
"unable to compute the parameters for SM=" <<
id.ism() <<
" xt=" <<
id.ic() <<
" " <<
id.rawId();
241 int tmpPedByGain = (
int)(peds->
mean(
i) + 0.5);
242 toCompressStream << std::hex <<
" 0x" << tmpPedByGain <<
" 0x" <<
mult <<
" 0x" <<
shift <<
" " <<
i2cSub_[
i]
247 tmpStringConv = toCompressStream.str();
248 tmpStringOut = tmpStringConv.c_str();
249 gzwrite(
out_file_, tmpStringOut, std::strlen(tmpStringOut));
254 std::vector<float> sampleSet;
255 std::vector<float> sampleDotSet;
256 std::vector<unsigned int> clockSampleSet;
257 double scaleMatrixBy = 1.;
272 clockSampleSet = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
275 switch (lbinOfMaximum) {
277 clockSampleSet = {2, 3, 4, 5, 6, 7, 8, 9};
280 clockSampleSet = {0, 1, 2, 3, 4, 5, 6, 7};
286 switch (lbinOfMaximum) {
288 clockSampleSet = {3, 4, 6, 7, 8, 9};
291 clockSampleSet = {1, 2, 4, 5, 6, 7};
297 clockSampleSet = {0, 1, 2, 3, 4, 5, 6, 7};
308 TMatrix fMat(clockSampleSet.size(), fMatColumns);
310 TMatrix gMat(fMatColumns, clockSampleSet.size());
314 std::vector<int> tmpWeightVec;
315 std::vector<int> tmpTimeWeightVec;
316 unsigned int iClock = 0;
317 for (
unsigned int iSample = 0; iSample < 12; iSample++) {
318 bool inSampleSet =
false;
319 for (
unsigned int clockSample = 0; clockSample < clockSampleSet.size(); clockSample++) {
320 if (iSample == clockSampleSet[clockSample]) {
322 iClock = clockSample;
328 tmpWeightVec.push_back(round(gMat(2, iClock) *
multToInt_));
330 tmpWeightVec.push_back(round(gMat(3, iClock) *
multToInt_));
333 tmpWeightVec.push_back(0);
335 tmpWeightVec.push_back(0);
343 UInt_t numPoints = graph.GetN();
345 edm::LogWarning(
"EcalEBPhase2TPParamProducer") <<
"Error! Wrong amount of points in pulse graph! ";
354 graph.GetPoint(
p + 1, xvalPOne, yvalPOne);
355 float midpoint = (xvalPOne +
xval) / 2;
356 float rise = yvalPOne -
yval;
358 deriv.SetPoint(deriv.GetN(), midpoint, rise /
run);
360 deriv.SetName(
"pulse_prime");
365 std::vector<float> sampleSet,
366 std::vector<float> sampleDotSet,
370 for (UInt_t
i = 0;
i < clockSampleSet.size();
i++) {
371 Int_t tmpClockToSample = clockSampleSet[
i] + iShift;
372 fMat(
i, 0) = sampleSet[tmpClockToSample];
373 fMat(
i, 1) = sampleDotSet[tmpClockToSample];
374 if (tmpClockToSample > 4) {
375 fMat(
i, 2) = sampleSet[tmpClockToSample - 4];
376 fMat(
i, 3) = sampleDotSet[tmpClockToSample - 4];
378 if (clockSampleSet[
i] > 8 && useThirdPulse) {
379 fMat(
i, 4) = sampleSet[tmpClockToSample - 8];
380 fMat(
i, 5) = sampleDotSet[tmpClockToSample - 8];
390 TMatrix InvFTDotF = FTDotF;
397 gMat *= scaleMatrixBy;
402 std::vector<float>& sampleSet) {
406 sampleSet.push_back(
y);
411 double theta,
double gainRatio,
double calibCoeff,
int&
shift,
int&
mult) {
static constexpr unsigned int NGAINS
const std::string outFile_
static const int linTopRange_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
const edm::ESGetToken< EcalLiteDTUPedestalsMap, EcalLiteDTUPedestalsRcd > theEcalTPGPedestals_Token_
const unsigned int binOfMaximum_
std::string fullPath() const
void getNumericalDeriv(TGraph graph, TGraph &deriv)
Sin< T >::type sin(const T &t)
Log< level::Error, false > LogError
float mean(unsigned int i) const
std::vector< int > computeWeights(int type)
~EcalEBPhase2TPParamProducer() override
void getGMatrix(TMatrix FMat, float scaleMatrixBy, TMatrix &GMat)
void fillFMat(std::vector< unsigned int > clockSampleSet, bool useThirdPulse, std::vector< float > sampleSet, std::vector< float > sampleDotSet, TMatrix &FMat, unsigned int binOfMaximum)
static constexpr unsigned int sampleSize
static constexpr double Samp_Period
const edm::ESGetToken< CaloSubdetectorGeometry, EcalBarrelGeometryRecord > theBarrelGeometryToken_
Abs< T >::type abs(const T &t)
#define DEFINE_FWK_MODULE(type)
bool computeLinearizerParam(double theta, double gainRatio, double calibCoeff, int &shift, int &mult)
static constexpr float norm_
constexpr float gains[NGAINS]
static constexpr float offset_
EcalEBPhase2TPParamProducer(edm::ParameterSet const &pSet)
std::vector< Item >::const_iterator const_iterator
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void getPulseSampleSet(TGraph pulseGraph, float phaseShift, std::vector< float > &sampleSet)
const unsigned int nWeightGroups_
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
static unsigned int const shift
Log< level::Warning, false > LogWarning
Geom::Theta< T > theta() const
const edm::FileInPath inFile_
static void fillDescriptions(edm::ConfigurationDescriptions &)
TPG Param Builder for Phase2