20 : nominal_gain_(0.), rctlsb_factor_(0.),
21 compressionFile_(compressionFile),
22 decompressionFile_(decompressionFile)
44 analyticalLUT[
i] = (
unsigned int)(
sqrt(14.94*
log(1.+
i/14.94)*
i) + 0.5);
45 identityLUT[
i] =
min(
i,0xffu);
48 for (
int ieta=-32; ieta <= 32; ieta++){
49 for (
int iphi = 1; iphi <= 72; iphi++){
50 if (!
HTvalid(ieta,iphi))
continue;
54 std::cout <<
"Error: LUT with (ieta,iphi) = (" << ieta <<
"," << iphi <<
") has been previously allocated!" << std::endl;
75 std::ifstream userfile;
76 std::vector< std::vector<LUT> > outputluts;
78 std::cout <<
"Initializing compression LUT's from " << (
char *)filename.data() << std::endl;
80 int maxid = 0, minid = 0x7FFFFFFF, rawid = 0;
81 for (
int ieta=-32; ieta <= 32; ieta++) {
82 for (
int iphi = 1; iphi <= 72; iphi++) {
85 if (
outputLUT_[rawid] != 0)
std::cout <<
"Error: LUT with (ieta,iphi) = (" << ieta <<
"," << iphi <<
") has been previously allocated!" << std::endl;
87 if (rawid < minid) minid = rawid;
88 if (rawid > maxid) maxid = rawid;
93 userfile.open((
char *)filename.data());
98 std::vector<int> loieta,hiieta;
99 std::vector<int> loiphi,hiiphi;
104 unsigned int index = 0;
105 while (index < s.length()) {
106 while (isspace(s[index])) index++;
107 if (index < s.length()) nluts++;
108 while (!isspace(s[index])) index++;
110 for (
unsigned int i=0;
i<=s.length();
i++) userfile.unget();
111 outputluts.resize(nluts);
115 for (
int i=0;
i<nluts;
i++) {
117 loieta.push_back(tool);
120 for (
int i=0;
i<nluts;
i++) {
122 hiieta.push_back(tool);
125 for (
int i=0;
i<nluts;
i++) {
127 loiphi.push_back(tool);
131 for (
int i=0;
i<nluts;
i++) {
133 hiiphi.push_back(tool);
138 for(
int i=0;
i <nluts;
i++) {
141 std::cout <<
"Error: LUT can't have negative numbers; 0 used instead: " <<
i <<
", " <<
j <<
" : = " << tool << std::endl;
143 }
else if (tool > 0xff) {
144 std::cout <<
"Error: LUT can't have >8-bit numbers; 0xff used instead: " <<
i <<
", " <<
j <<
" : = " << tool << std::endl;
147 outputluts[
i][
j] = tool;
148 if (userfile.eof())
std::cout <<
"Error: LUT file is truncated or has a wrong format: " <<
i <<
"," <<
j << std::endl;
155 for (
int i=0;
i < nluts;
i++) {
157 for (
int iphi = loiphi[
i]; iphi <= hiiphi[
i]; iphi++) {
158 for (
int ieta=loieta[
i]; ieta <= hiieta[
i]; ieta++) {
161 if (
outputLUT_[
id] == 0)
throw cms::Exception(
"PROBLEM: outputLUT_ has not been initialized for ieta, iphi, id = ") << ieta <<
", " << iphi <<
", " <<
id << std::endl;
185 for (
int ieta = -32; ieta <= 32; ++ieta){
187 double eta_low = 0., eta_high = 0.;
189 double cosh_ieta = fabs(cosh((eta_low + eta_high)/2.));
191 for (
int iphi = 1; iphi <= 72; iphi++) {
192 if (!
HTvalid(ieta, iphi))
continue;
212 unsigned int mid = (low +
i)/2;
213 hcaluncomp_[lutId][tpg] = (tpg == 0 ? low : factor * mid);
224 std::ifstream userfile;
225 userfile.open(filename.c_str());
230 static const int etabound = 32;
234 for(
int j = 1;
j <=etabound;
j++) {
236 for (
int iphi = 1; iphi <= 72; iphi++) {
253 int ieta =
id.ieta();
254 int iphi =
id.iphi();
258 if (itower < 0)
cms::Exception(
"Invalid Data") <<
"No trigger tower found for ieta, iphi = " << ieta <<
", " << iphi;
261 throw cms::Exception(
"Out of Range") <<
"LUT has 1024 entries for " << itower <<
" but " << sample <<
" was requested.";
271 if (itower < 0)
std::cout <<
"hcaletValue error: no decompression LUT found for ieta, iphi = " << ieta <<
", " << iphi << std::endl;
272 else if (compET < 0 || compET > 0xff)
std::cout <<
"hcaletValue error: compressed value out of range: eta, phi, cET = " << ieta <<
", " << iphi <<
", " << compET << std::endl;
282 if (compET < 0 || compET > 0xff)
std::cout <<
"hcaletValue error: compressed value out of range: eta, cET = " << ieta <<
", " << compET << std::endl;
285 for (
int iphi=1; iphi <= 72; iphi++) {
292 if (nphi > 0) etvalue /= nphi;
293 else std::cout <<
"hcaletValue error: no decompression LUTs found for any iphi for ieta = " << ieta << std::endl;
300 int ieta = hid.
ieta();
301 int iphi = hid.
iphi();
309 throw cms::Exception(
"Not Implemented") <<
"CaloTPGTranscoderULUT::ecalCompress";
314 unsigned int& et,
bool& egVecto,
bool& activity)
const {
315 throw cms::Exception(
"Not Implemented") <<
"CaloTPGTranscoderULUT::rctEGammaUncompress";
319 unsigned int& et)
const {
320 throw cms::Exception(
"Not Implemented") <<
"CaloTPGTranscoderULUT::rctJetUncompress";
325 if (iphi <= 0 || iphi > 72 || ieta == 0 ||
abs(ieta) > 32)
return false;
326 if (
abs(ieta) > 28) {
328 if ((iphi/4)*4 + 1 != iphi)
return false;
331 if (iphi > 18)
return false;
342 if (ietaabs < 29)
return 72*(ietaabs - 1) + (iphi - 1) +
offset;
345 return 18*(ietaabs - 29) + iphi + 2015 + offset;
351 std::vector<unsigned char>
lut;
364 if (rctlsb != 0.25 && rctlsb != 0.5)
365 throw cms::Exception(
"RCTLSB") <<
" value=" << rctlsb <<
" (should be 0.25 or 0.5)" << std::endl;
373 std::cout <<
"From Text File:" << std::endl;
std::vector< RCTdecompression > hcaluncomp_
std::string decompressionFile_
CaloTPGTranscoderULUT(const std::string &compressionFile="", const std::string &decompressionFile="")
const Item * getValues(DetId fId, bool throwOnFail=true) const
virtual std::vector< unsigned char > getCompressionLUT(HcalTrigTowerDetId id) const
void loadHCALUncompress(HcalLutMetadata const &, HcalTrigTowerGeometry const &)
int ieta() const
get the tower ieta
virtual ~CaloTPGTranscoderULUT()
virtual void rctJetUncompress(const HcalTrigTowerDetId &hid, const HcalTriggerPrimitiveSample &hc, const EcalTrigTowerDetId &eid, const EcalTriggerPrimitiveSample &ec, unsigned int &et) const
Uncompression for the JET path in the RCT.
Abs< T >::type abs(const T &t)
static const unsigned int OUTPUT_LUT_SIZE
virtual void rctEGammaUncompress(const HcalTrigTowerDetId &hid, const HcalTriggerPrimitiveSample &hc, const EcalTrigTowerDetId &eid, const EcalTriggerPrimitiveSample &ec, unsigned int &et, bool &egVecto, bool &activity) const
Uncompression for the Electron/Photon path in the RCT.
virtual bool HTvalid(const int ieta, const int iphi) const
void loadHCALCompress(HcalLutMetadata const &, HcalTrigTowerGeometry const &)
void towerEtaBounds(int ieta, double &eta1, double &eta2) const
where this tower begins and ends in eta
LUT * outputLUT_[NOUTLUTS]
std::vector< double > RCTdecompression
std::string compressionFile_
virtual void setup(HcalLutMetadata const &, HcalTrigTowerGeometry const &)
virtual double hcaletValue(const int &ieta, const int &compressedValue) const
static const int NOUTLUTS
virtual int getOutputLUTId(const int ieta, const int iphi) const
int compressedEt() const
get the encoded/compressed Et
virtual EcalTriggerPrimitiveSample ecalCompress(const EcalTrigTowerDetId &id, unsigned int sample, bool fineGrain) const
Compression from linear samples+fine grain in the ECAL.
static const bool newHFphi
virtual HcalTriggerPrimitiveSample hcalCompress(const HcalTrigTowerDetId &id, unsigned int sample, bool fineGrain) const
Compression from linear samples+fine grain in the HTR.
int iphi() const
get the tower iphi