CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloTPGTranscoderULUT.cc
Go to the documentation of this file.
8 #include <iostream>
9 #include <fstream>
10 #include <math.h>
11 
12 //#include "FWCore/Framework/interface/Frameworkfwd.h"
16 
17 using namespace std;
18 
20  const std::string& decompressionFile)
21  : theTopology(0),
22  nominal_gain_(0.), lsb_factor_(0.), rct_factor_(1.), nct_factor_(1.),
23  compressionFile_(compressionFile),
24  decompressionFile_(decompressionFile)
25 {
26 }
27 
29 }
30 
32  HcalTrigTowerGeometry const& theTrigTowerGeometry) {
33  if (!theTopology) {
34  throw cms::Exception("CaloTPGTranscoderULUT") << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
35  }
36 
37  std::array<unsigned int, OUTPUT_LUT_SIZE> analytical10BITLUT;
38  std::array<unsigned int, OUTPUT_LUT_SIZE> analytical11BITLUT;
39  std::array<unsigned int, OUTPUT_LUT_SIZE> linearRctLUT;
40  std::array<unsigned int, OUTPUT_LUT_SIZE> linearNctLUT;
41 
42  // Compute compression LUT
43  for (unsigned int i=0; i < OUTPUT_LUT_SIZE; i++) {
44  analytical10BITLUT[i] = (unsigned int)(sqrt(14.94*log(1.+i/14.94)*i) + 0.5);
45  analytical11BITLUT[i] = (unsigned int)(sqrt(5.32*log(1.+i/5.32)*i) + 0.5);
46  linearRctLUT[i] = min((unsigned int)(i/rct_factor_), TPGMAX - 1);
47  linearNctLUT[i] = min((unsigned int)(i/nct_factor_), TPGMAX - 1);
48  }
49 
50  std::vector<DetId> allChannels = lutMetadata.getAllChannels();
51 
52  for(std::vector<DetId>::iterator i=allChannels.begin(); i!=allChannels.end(); ++i){
53 
54  if (not HcalGenericDetId(*i).isHcalTrigTowerDetId()) {
55  if ((not HcalGenericDetId(*i).isHcalDetId()) and
56  (not HcalGenericDetId(*i).isHcalZDCDetId()) and
58  edm::LogWarning("CaloTPGTranscoderULUT") << "Encountered invalid HcalDetId " << HcalGenericDetId(*i);
59  continue;
60  }
61 
62  HcalTrigTowerDetId id(*i);
63  if(!theTopology->validHT(id)) continue;
64 
65  unsigned int index = getOutputLUTId(id);
66 
67  const HcalLutMetadatum *meta = lutMetadata.getValues(id);
68  unsigned int threshold = meta->getOutputLutThreshold();
69 
70  int ieta=id.ieta();
71  int version=id.version();
72  bool isHBHE = (abs(ieta) < theTrigTowerGeometry.firstHFTower(version));
73 
74  unsigned int lutsize = getOutputLUTSize(id);
75 
76  for (unsigned int i = 0; i < threshold; ++i)
77  outputLUT_[index][i] = 0;
78 
79  if (isHBHE and lutsize == REDUCE10BIT) {
80  for (unsigned int i = threshold; i < lutsize; ++i)
81  outputLUT_[index][i] = analytical10BITLUT[i];
82  } else if (isHBHE) {
83  for (unsigned int i = threshold; i < lutsize; ++i)
84  outputLUT_[index][i] = analytical11BITLUT[i];
85  } else {
86  for (unsigned int i = threshold; i < lutsize; ++i)
87  outputLUT_[index][i] = version == 0 ? linearRctLUT[i] : linearNctLUT[i];
88  }
89 
90  double eta_low = 0., eta_high = 0.;
91  theTrigTowerGeometry.towerEtaBounds(ieta,version,eta_low,eta_high);
92  double cosh_ieta = fabs(cosh((eta_low + eta_high)/2.));
93  double granularity = meta->getLutGranularity();
94 
95  if(isHBHE){
96  double factor = nominal_gain_ / cosh_ieta * granularity;
97  LUT tpg = outputLUT_[index][0];
98  int low = 0;
99  for (unsigned int i = 0; i < getOutputLUTSize(id); ++i){
100  if (outputLUT_[index][i] != tpg){
101  unsigned int mid = (low + i)/2;
102  hcaluncomp_[index][tpg] = (tpg == 0 ? low : factor * mid);
103  low = i;
104  tpg = outputLUT_[index][i];
105  }
106  }
107  hcaluncomp_[index][tpg] = factor * low;
108  }
109  else{
110  LUT tpg = outputLUT_[index][0];
111  hcaluncomp_[index][tpg]=0;
112  for (unsigned int i = 0; i < getOutputLUTSize(id); ++i){
113  if (outputLUT_[index][i] != tpg){
114  tpg = outputLUT_[index][i];
115  hcaluncomp_[index][tpg] = lsb_factor_ * i / (version==0?rct_factor_:nct_factor_);
116  }
117  }
118  }
119  }
120 }
121 
123  unsigned int itower = getOutputLUTId(id);
124 
125  if (sample >= getOutputLUTSize(id))
126  throw cms::Exception("Out of Range")
127  << "LUT has " << getOutputLUTSize(id) << " entries for " << itower << " but " << sample << " was requested.";
128 
129  if(itower >= outputLUT_.size())
130  throw cms::Exception("Out of Range") << "No decompression LUT found for " << id;
131 
132  return HcalTriggerPrimitiveSample(outputLUT_[itower][sample], fineGrain);
133 }
134 
135 double CaloTPGTranscoderULUT::hcaletValue(const int& ieta, const int& iphi, const int& version, const int& compET) const {
136  double etvalue = 0.;
137  int itower = getOutputLUTId(ieta,iphi, version);
138  if (itower < 0) {
139  edm::LogError("CaloTPGTranscoderULUT") << "No decompression LUT found for ieta, iphi = " << ieta << ", " << iphi;
140  } else if (compET < 0 || compET >= (int) TPGMAX) {
141  edm::LogError("CaloTPGTranscoderULUT") << "Compressed value out of range: eta, phi, cET = " << ieta << ", " << iphi << ", " << compET;
142  } else {
143  etvalue = hcaluncomp_[itower][compET];
144  }
145  return(etvalue);
146 }
147 
149  int compET = hc.compressedEt(); // to be within the range by the class
150  int itower = getOutputLUTId(hid);
151  double etvalue = hcaluncomp_[itower][compET];
152  return etvalue;
153 }
154 
156  throw cms::Exception("Not Implemented") << "CaloTPGTranscoderULUT::ecalCompress";
157 }
158 
161  unsigned int& et, bool& egVecto, bool& activity) const {
162  throw cms::Exception("Not Implemented") << "CaloTPGTranscoderULUT::rctEGammaUncompress";
163 }
166  unsigned int& et) const {
167  throw cms::Exception("Not Implemented") << "CaloTPGTranscoderULUT::rctJetUncompress";
168 }
169 
170 bool CaloTPGTranscoderULUT::HTvalid(const int ieta, const int iphiin, const int version) const {
171  HcalTrigTowerDetId id(ieta, iphiin);
172  id.setVersion(version);
173  if (!theTopology) {
174  throw cms::Exception("CaloTPGTranscoderULUT") << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
175  }
176  return theTopology->validHT(id);
177 }
178 
180  if (!theTopology) {
181  throw cms::Exception("CaloTPGTranscoderULUT") << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
182  }
183  return theTopology->detId2denseIdHT(id);
184 }
185 
186 int CaloTPGTranscoderULUT::getOutputLUTId(const int ieta, const int iphiin, const int version) const {
187  if (!theTopology) {
188  throw cms::Exception("CaloTPGTranscoderULUT") << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
189  }
190  HcalTrigTowerDetId id(ieta, iphiin);
191  id.setVersion(version);
192  return theTopology->detId2denseIdHT(id);
193 }
194 
195 unsigned int
197 {
198  if (!theTopology)
199  throw cms::Exception("CaloTPGTranscoderULUT")
200  << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
201 
202  switch (theTopology->triggerMode()) {
205  return QIE8_OUTPUT_LUT_SIZE;
207  if (id.ietaAbs() <= theTopology->lastHBRing())
208  return QIE8_OUTPUT_LUT_SIZE;
209  else if (id.ietaAbs() <= theTopology->lastHERing())
210  return QIE11_OUTPUT_LUT_SIZE;
211  else
212  return QIE10_OUTPUT_LUT_SIZE;
213  default:
214  throw cms::Exception("CaloTPGTranscoderULUT")
215  << "Unknown trigger mode used by the topology!";
216  }
217 }
218 
219 const std::vector<unsigned int> CaloTPGTranscoderULUT::getCompressionLUT(const HcalTrigTowerDetId& id) const {
220  int itower = getOutputLUTId(id);
221  auto lut = outputLUT_[itower];
222  std::vector<unsigned int> result(lut.begin(), lut.end());
223  return result;
224 }
225 
226 void CaloTPGTranscoderULUT::setup(HcalLutMetadata const& lutMetadata, HcalTrigTowerGeometry const& theTrigTowerGeometry, int nctScaleShift, int rctScaleShift)
227 {
228  theTopology = lutMetadata.topo();
229  nominal_gain_ = lutMetadata.getNominalGain();
230  lsb_factor_ = lutMetadata.getRctLsb();
231 
232  rct_factor_ = lsb_factor_/(HcaluLUTTPGCoder::lsb_*(1<<rctScaleShift));
233  nct_factor_ = lsb_factor_/(HcaluLUTTPGCoder::lsb_*(1<<nctScaleShift));
234 
235  outputLUT_.resize(theTopology->getHTSize());
236  hcaluncomp_.resize(theTopology->getHTSize());
237 
238  if (compressionFile_.empty() && decompressionFile_.empty()) {
239  loadHCALCompress(lutMetadata,theTrigTowerGeometry);
240  }
241  else {
242  throw cms::Exception("Not Implemented") << "setup of CaloTPGTranscoderULUT from text files";
243  }
244 }
static const unsigned int REDUCE10BIT
int i
Definition: DBlmapReader.cc:9
std::vector< RCTdecompression > hcaluncomp_
std::vector< std::array< LUT, OUTPUT_LUT_SIZE > > outputLUT_
bool isHcalZDCDetId() const
static const unsigned int QIE8_OUTPUT_LUT_SIZE
uint8_t getOutputLutThreshold() const
virtual bool HTvalid(const int ieta, const int iphi, const int version) const
unsigned int detId2denseIdHT(const DetId &id) const
return a linear packed id from HT
unsigned int getOutputLUTSize(const HcalTrigTowerDetId &id) const
virtual const std::vector< unsigned int > getCompressionLUT(const HcalTrigTowerDetId &id) const
int lastHBRing() const
Definition: HcalTopology.h:84
static const float lsb_
void towerEtaBounds(int ieta, int version, double &eta1, double &eta2) const
where this tower begins and ends in eta
CaloTPGTranscoderULUT(const std::string &compressionFile="", const std::string &decompressionFile="")
const Item * getValues(DetId fId, bool throwOnFail=true) const
uint8_t getLutGranularity() const
HcalTopologyMode::TriggerMode triggerMode() const
Definition: HcalTopology.h:32
virtual void rctJetUncompress(const HcalTrigTowerDetId &hid, const HcalTriggerPrimitiveSample &hc, const EcalTrigTowerDetId &eid, const EcalTriggerPrimitiveSample &ec, unsigned int &et) const override
Uncompression for the JET path in the RCT.
tuple result
Definition: mps_fire.py:84
virtual HcalTriggerPrimitiveSample hcalCompress(const HcalTrigTowerDetId &id, unsigned int sample, int fineGrain) const override
Compression from linear samples+fine grain in the HTR.
bool isHcalTrigTowerDetId() const
const HcalTopology * theTopology
std::vector< DetId > getAllChannels() const
T sqrt(T t)
Definition: SSEVec.h:18
float getNominalGain() const
static const unsigned int QIE10_OUTPUT_LUT_SIZE
virtual int getOutputLUTId(const HcalTrigTowerDetId &id) const
virtual void rctEGammaUncompress(const HcalTrigTowerDetId &hid, const HcalTriggerPrimitiveSample &hc, const EcalTrigTowerDetId &eid, const EcalTriggerPrimitiveSample &ec, unsigned int &et, bool &egVecto, bool &activity) const override
Uncompression for the Electron/Photon path in the RCT.
unsigned int getHTSize() const
Definition: HcalTopology.h:125
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const unsigned int OUTPUT_LUT_SIZE
tuple lut
Definition: lumiPlot.py:244
T min(T a, T b)
Definition: MathUtil.h:58
bool isHcalDetId() const
void loadHCALCompress(HcalLutMetadata const &, HcalTrigTowerGeometry const &)
virtual void setup(HcalLutMetadata const &, HcalTrigTowerGeometry const &, int, int)
virtual EcalTriggerPrimitiveSample ecalCompress(const EcalTrigTowerDetId &id, unsigned int sample, bool fineGrain) const override
Compression from linear samples+fine grain in the ECAL.
static const unsigned int QIE11_OUTPUT_LUT_SIZE
float getRctLsb() const
static const unsigned int TPGMAX
susybsm::HSCParticleCollection hc
Definition: classes.h:25
int compressedEt() const
get the encoded/compressed Et
bool isHcalCastorDetId() const
virtual double hcaletValue(const int &ieta, const int &iphi, const int &version, const int &compressedValue) const override
int lastHERing() const
Definition: HcalTopology.h:86
const HcalTopology * topo() const
bool validHT(const HcalTrigTowerDetId &id) const
int firstHFTower(int version) const