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_;
90 throw cms::Exception(
"BadInitialization") <<
"provided list of encoder graphs have different input nodes";
93 throw cms::Exception(
"BadInitialization") <<
"provided list of encoder graphs have different output nodes";
96 throw cms::Exception(
"BadInitialization") <<
"provided list of decoder graphs have different input nodes";
99 throw cms::Exception(
"BadInitialization") <<
"provided list of decoder graphs have different output nodes";
107 <<
"Autoencoder graph number must be specified for all link allocation possibilities. Only " 115 <<
"Autoencoder graph number " << graphNumber <<
" is larger than the size of the provided list of graphs " 122 const std::vector<l1t::HGCalTriggerCell>& trigCellVecInput,
123 std::vector<l1t::HGCalTriggerCell>& trigCellVecOutput,
124 std::vector<l1t::HGCalConcentratorData>& ae_encodedLayer_Output) {
125 std::array<double, nTriggerCells_> mipPt;
126 std::array<double, nTriggerCells_> uncompressedCharge;
127 std::array<double, nTriggerCells_> compressedCharge;
128 std::array<double, maxAEInputSize_> ae_inputArray;
129 std::array<double, nTriggerCells_> ae_outputArray;
133 uncompressedCharge.fill(0);
134 compressedCharge.fill(0);
135 ae_inputArray.fill(0);
136 ae_outputArray.fill(0);
144 double inputMaxIntSize = 1;
147 double outputMaxIntSize = 1;
148 if (bitsPerOutput > 0)
149 outputMaxIntSize = 1 << bitsPerOutput;
150 double outputMaxIntSizeGlobal = 1;
154 for (
const auto& trigCell : trigCellVecInput) {
159 uint cellu =
id.triggerCellU();
160 uint cellv =
id.triggerCellV();
162 if (inputIndex < 0) {
164 <<
"Invalid index provided for trigger cell u=" << cellu <<
" v=" << cellv <<
" in cellUVRemap[" << cellu
165 <<
"][" << cellv <<
"]";
168 mipPt[inputIndex] = trigCell.mipPt();
169 uncompressedCharge[inputIndex] = trigCell.uncompressedCharge();
170 compressedCharge[inputIndex] = trigCell.compressedCharge();
172 modSum += trigCell.mipPt();
180 int msb =
int(log2(modSum));
192 ae_inputArray[
i] = std::round(ae_inputArray[
i] * inputMaxIntSize) / inputMaxIntSize;
197 tensorflow::Tensor encoder_input(tensorflow::DT_FLOAT,
200 float*
d = encoder_input.flat<
float>().
data();
202 *
d = ae_inputArray[
i];
207 std::vector<tensorflow::Tensor> encoder_outputs;
213 if (encoder_outputs.empty()) {
214 throw cms::Exception(
"BadInitialization") <<
"Autoencoder graph returning empty output vector";
217 d = encoder_outputs[0].flat<
float>().
data();
218 for (
int i = 0;
i < encoder_outputs[0].NumElements();
i++,
d++) {
227 d = decoder_input.flat<
float>().
data();
232 std::vector<tensorflow::Tensor> decoder_outputs;
238 double outputSum = 0.;
240 d = decoder_outputs[0].flat<
float>().
data();
246 ae_outputArray[remapIndex] = *
d;
249 double renormalizationFactor = 1.;
251 renormalizationFactor = modSum / outputSum;
258 int subdet =
id.subdet();
260 int type =
id.type();
261 int layer =
id.layer();
266 float mipPtToEt_conv = trigCellVecInput[0].et() / trigCellVecInput[0].mipPt();
267 float mipToADC_conv = trigCellVecInput[0].hwPt() / (trigCellVecInput[0].mipPt() * cosh(trigCellVecInput[0].
eta()));
270 if (ae_outputArray[
i] > 0) {
281 double mipPt = ae_outputArray[
i] *
normalization * renormalizationFactor;
282 double adc = mipPt * cosh(
point.eta()) * mipToADC_conv;
283 double et = mipPt * mipPtToEt_conv;
296 triggerCell.
setP4(p4);
299 trigCellVecOutput.push_back(triggerCell);
307 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_
void setLogging(const std::string &level="3")
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.
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_