9 : cellRemap_(conf.getParameter<
std::
vector<
int>>(
"cellRemap")),
10 cellRemapNoDuplicates_(conf.getParameter<
std::
vector<
int>>(
"cellRemapNoDuplicates")),
11 encoderShape_(conf.getParameter<
std::
vector<
uint>>(
"encoderShape")),
12 decoderShape_(conf.getParameter<
std::
vector<
uint>>(
"decoderShape")),
13 bitsPerInput_(conf.getParameter<
int>(
"nBitsPerInput")),
14 maxBitsPerOutput_(conf.getParameter<
int>(
"maxBitsPerOutput")),
15 outputBitsPerLink_(conf.getParameter<
std::
vector<
int>>(
"bitsPerLink")),
17 linkToGraphMap_(conf.getParameter<
std::
vector<unsigned
int>>(
"linkToGraphMap")),
18 zeroSuppresionThreshold_(conf.getParameter<double>(
"zeroSuppresionThreshold")),
19 bitShiftNormalization_(conf.getParameter<
bool>(
"bitShiftNormalization")),
20 saveEncodedValues_(conf.getParameter<
bool>(
"saveEncodedValues")),
21 preserveModuleSum_(conf.getParameter<
bool>(
"preserveModuleSum")) {
32 <<
"Encoder input shapes are currently expected to be " <<
encoderTensorDims_ <<
" values";
37 <<
"Encoder input shapes are currently expected to be " <<
decoderTensorDims_ <<
" values long";
43 <<
") does not agree with the total size specified for the encoder inputs based on the encoderShape variable (" 49 <<
"Size of cellRemap (" <<
cellRemap_.size() <<
") does not agree with size of cellRemapNoDuplicates (" 60 <<
" is larger than the number of trigger cells " <<
nTriggerCells_;
88 throw cms::Exception(
"BadInitialization") <<
"provided list of encoder graphs have different input nodes";
91 throw cms::Exception(
"BadInitialization") <<
"provided list of encoder graphs have different output nodes";
94 throw cms::Exception(
"BadInitialization") <<
"provided list of decoder graphs have different input nodes";
97 throw cms::Exception(
"BadInitialization") <<
"provided list of decoder graphs have different output nodes";
105 <<
"Autoencoder graph number must be specified for all link allocation possibilities. Only " 113 <<
"Autoencoder graph number " << graphNumber <<
" is larger than the size of the provided list of graphs " 120 const std::vector<l1t::HGCalTriggerCell>& trigCellVecInput,
121 std::vector<l1t::HGCalTriggerCell>& trigCellVecOutput,
122 std::vector<l1t::HGCalConcentratorData>& ae_encodedLayer_Output) {
123 std::array<double, nTriggerCells_> mipPt;
124 std::array<double, nTriggerCells_> uncompressedCharge;
125 std::array<double, nTriggerCells_> compressedCharge;
126 std::array<double, maxAEInputSize_> ae_inputArray;
127 std::array<double, nTriggerCells_> ae_outputArray;
131 uncompressedCharge.fill(0);
132 compressedCharge.fill(0);
133 ae_inputArray.fill(0);
134 ae_outputArray.fill(0);
142 double inputMaxIntSize = 1;
145 double outputMaxIntSize = 1;
146 if (bitsPerOutput > 0)
147 outputMaxIntSize = 1 << bitsPerOutput;
148 double outputMaxIntSizeGlobal = 1;
152 for (
const auto& trigCell : trigCellVecInput) {
157 uint cellu =
id.triggerCellU();
158 uint cellv =
id.triggerCellV();
160 if (inputIndex < 0) {
162 <<
"Invalid index provided for trigger cell u=" << cellu <<
" v=" << cellv <<
" in cellUVRemap[" << cellu
163 <<
"][" << cellv <<
"]";
166 mipPt[inputIndex] = trigCell.mipPt();
167 uncompressedCharge[inputIndex] = trigCell.uncompressedCharge();
168 compressedCharge[inputIndex] = trigCell.compressedCharge();
170 modSum += trigCell.mipPt();
178 int msb =
int(log2(modSum));
190 ae_inputArray[
i] = std::round(ae_inputArray[
i] * inputMaxIntSize) / inputMaxIntSize;
195 tensorflow::Tensor encoder_input(tensorflow::DT_FLOAT,
198 float*
d = encoder_input.flat<
float>().
data();
200 *
d = ae_inputArray[
i];
205 std::vector<tensorflow::Tensor> encoder_outputs;
211 if (encoder_outputs.empty()) {
212 throw cms::Exception(
"BadInitialization") <<
"Autoencoder graph returning empty output vector";
215 d = encoder_outputs[0].flat<
float>().
data();
216 for (
int i = 0;
i < encoder_outputs[0].NumElements();
i++,
d++) {
225 d = decoder_input.flat<
float>().
data();
230 std::vector<tensorflow::Tensor> decoder_outputs;
236 double outputSum = 0.;
238 d = decoder_outputs[0].flat<
float>().
data();
244 ae_outputArray[remapIndex] = *
d;
247 double renormalizationFactor = 1.;
249 renormalizationFactor = modSum / outputSum;
256 int subdet =
id.subdet();
258 int type =
id.type();
259 int layer =
id.layer();
264 float mipPtToEt_conv = trigCellVecInput[0].et() / trigCellVecInput[0].mipPt();
265 float mipToADC_conv = trigCellVecInput[0].hwPt() / (trigCellVecInput[0].mipPt() * cosh(trigCellVecInput[0].
eta()));
268 if (ae_outputArray[
i] > 0) {
279 double mipPt = ae_outputArray[
i] *
normalization * renormalizationFactor;
280 double adc = mipPt * cosh(
point.eta()) * mipToADC_conv;
281 double et = mipPt * mipPtToEt_conv;
294 triggerCell.
setP4(p4);
297 trigCellVecOutput.push_back(triggerCell);
305 ae_encodedLayer_Output.push_back(encodedLayerData);
static constexpr int decoderTensorDims_
std::vector< uint > decoderShape_
static constexpr int nEncodedLayerNodes_
std::vector< uint > encoderShape_
std::string outputTensorName_encoder_
int32_t waferU(const int32_t index)
GraphDef * loadGraphDef(const std::string &pbFile)
std::string inputTensorName_encoder_
std::string outputTensorName_decoder_
static constexpr int ae_outputCellU_[nTriggerCells_]
bool bitShiftNormalization_
std::vector< std::unique_ptr< tensorflow::Session > > session_decoder_
std::unique_ptr< tensorflow::GraphDef > graphDef_encoder_
std::vector< std::unique_ptr< tensorflow::Session > > session_encoder_
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
virtual bool validTriggerCell(const unsigned trigger_cell_id) const =0
HGCalConcentratorAutoEncoderImpl(const edm::ParameterSet &conf)
static constexpr int cellUVremap_[cellUVSize_][cellUVSize_]
void setMipPt(double value)
static constexpr int encoderTensorDims_
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
HGCalTriggerTools triggerTools_
void setCompressedCharge(uint32_t value)
std::vector< int > outputBitsPerLink_
double zeroSuppresionThreshold_
Session * createSession()
std::unique_ptr< tensorflow::GraphDef > graphDef_decoder_
std::vector< int > cellRemapNoDuplicates_
std::vector< int > cellRemap_
void setUncompressedCharge(uint32_t value)
static constexpr int nTriggerCells_
static constexpr unsigned int maxNumberOfLinks_
std::vector< unsigned int > linkToGraphMap_
char data[epos_bytes_allocation]
int32_t waferV(const int32_t index)
void select(unsigned nLinks, const std::vector< l1t::HGCalTriggerCell > &trigCellVecInput, std::vector< l1t::HGCalTriggerCell > &trigCellVecOutput, std::vector< l1t::HGCalConcentratorData > &ae_EncodedOutput)
std::string inputTensorName_decoder_
static constexpr int ae_outputCellV_[nTriggerCells_]
void setPosition(const GlobalPoint &position)
void setP4(const LorentzVector &p4) final
set 4-momentum
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Power< A, B >::type pow(const A &a, const B &b)
std::vector< edm::ParameterSet > modelFilePaths_
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
uint16_t *__restrict__ uint16_t const *__restrict__ adc
std::array< double, nEncodedLayerNodes_ > ae_encodedLayer_