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"
15 
16 using namespace std;
17 
20 
22  const std::string& decompressionFile)
23  : theTopology(0),
24  nominal_gain_(0.), rctlsb_factor_(0.),
25  compressionFile_(compressionFile),
26  decompressionFile_(decompressionFile)
27 {
28  outputLUT_.clear();
29 }
30 
32 }
33 
35  HcalTrigTowerGeometry const& theTrigTowerGeometry) {
36  // Initialize analytical compression LUT's here
37  if (OUTPUT_LUT_SIZE != (unsigned int) 0x400)
38  edm::LogError("CaloTPGTranscoderULUT") << "Analytic compression expects 10-bit LUT; found LUT with " << OUTPUT_LUT_SIZE << " entries instead";
39 
40  if (!theTopology) {
41  throw cms::Exception("CaloTPGTranscoderULUT") << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
42  }
43 
44  std::array<unsigned int, OUTPUT_LUT_SIZE> analyticalLUT;
45  std::array<unsigned int, OUTPUT_LUT_SIZE> identityLUT;
46 
47  // Compute compression LUT
48  for (unsigned int i=0; i < OUTPUT_LUT_SIZE; i++) {
49  analyticalLUT[i] = (unsigned int)(sqrt(14.94*log(1.+i/14.94)*i) + 0.5);
50  identityLUT[i] = min(i, TPGMAX - 1);
51  }
52 
53  std::vector<DetId> allChannels = lutMetadata.getAllChannels();
54 
55  for(std::vector<DetId>::iterator i=allChannels.begin(); i!=allChannels.end(); ++i){
56 
57  if (not HcalGenericDetId(*i).isHcalTrigTowerDetId()) {
58  if (not HcalGenericDetId(*i).isHcalDetId())
59  edm::LogWarning("CaloTPGTranscoderULUT") << "Encountered invalid HcalDetId " << HcalGenericDetId(*i);
60  continue;
61  }
62 
63  HcalTrigTowerDetId id(*i);
64  if(!theTopology->validHT(id)) continue;
65 
66 
67  unsigned int index = getOutputLUTId(id);
68 
69  if(index >= outputLUT_.size()){
70  outputLUT_.resize(index+1);
71  hcaluncomp_.resize(index+1);
72  }
73 
74  const HcalLutMetadatum *meta = lutMetadata.getValues(id);
75  unsigned int threshold = meta->getOutputLutThreshold();
76 
77  int ieta=id.ieta();
78  int version=id.version();
79  bool isHBHE = (abs(ieta) < theTrigTowerGeometry.firstHFTower(version));
80 
81  for (unsigned int i = 0; i < threshold; ++i) outputLUT_[index].push_back(0);
82  for (unsigned int i = threshold; i < OUTPUT_LUT_SIZE; ++i){
83  LUT value = isHBHE ? analyticalLUT[i] : identityLUT[i];
84  outputLUT_[index].push_back(value);
85  }
86 
87  //now uncompression LUTs
88  hcaluncomp_[index].resize(TPGMAX);
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  double factor = isHBHE ? (nominal_gain_ / cosh_ieta * granularity) : rctlsb_factor_;
96 
97  LUT tpg = outputLUT_[index][0];
98  int low = 0;
99  for (unsigned int i = 0; i < OUTPUT_LUT_SIZE; ++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 }
110 
112  int itower = getOutputLUTId(id);
113 
114  if (sample >= OUTPUT_LUT_SIZE) {
115  throw cms::Exception("Out of Range") << "LUT has 1024 entries for " << itower << " but " << sample << " was requested.";
116  sample=OUTPUT_LUT_SIZE - 1;
117  }
118 
119  return HcalTriggerPrimitiveSample(outputLUT_[itower][sample],fineGrain,0,0);
120 }
121 
122 double CaloTPGTranscoderULUT::hcaletValue(const int& ieta, const int& iphi, const int& compET) const {
123  double etvalue = 0.;
124  int itower = getOutputLUTId(ieta,iphi);
125  if (itower < 0) {
126  edm::LogError("CaloTPGTranscoderULUT") << "No decompression LUT found for ieta, iphi = " << ieta << ", " << iphi;
127  } else if (compET < 0 || compET >= (int) TPGMAX) {
128  edm::LogError("CaloTPGTranscoderULUT") << "Compressed value out of range: eta, phi, cET = " << ieta << ", " << iphi << ", " << compET;
129  } else {
130  etvalue = hcaluncomp_[itower][compET];
131  }
132  return(etvalue);
133 }
134 
135 double CaloTPGTranscoderULUT::hcaletValue(const int& ieta, const int& compET) const {
136 // This is now an obsolete method; we return the AVERAGE over all the allowed iphi channels if it's invoked
137 // The user is encouraged to use hcaletValue(const int& ieta, const int& iphi, const int& compET) instead
138 
139  double etvalue = 0.;
140  if (compET < 0 || compET >= (int) TPGMAX) {
141  edm::LogError("CaloTPGTranscoderULUT") << "Compressed value out of range: eta, cET = " << ieta << ", " << compET;
142  } else {
143  int nphi = 0;
144  for (int iphi=1; iphi <= 72; iphi++) {
145  if (HTvalid(ieta,iphi)) {
146  nphi++;
147  int itower = getOutputLUTId(ieta,iphi);
148  etvalue += hcaluncomp_[itower][compET];
149  }
150  }
151  if (nphi > 0) {
152  etvalue /= nphi;
153  } else {
154  edm::LogError("CaloTPGTranscoderULUT") << "No decompression LUTs found for any iphi for ieta = " << ieta;
155  }
156  }
157  return(etvalue);
158 }
159 
161  int compET = hc.compressedEt(); // to be within the range by the class
162  int itower = getOutputLUTId(hid);
163  double etvalue = hcaluncomp_[itower][compET];
164  return etvalue;
165 }
166 
168  throw cms::Exception("Not Implemented") << "CaloTPGTranscoderULUT::ecalCompress";
169 }
170 
172  const EcalTrigTowerDetId& eid, const EcalTriggerPrimitiveSample& ec,
173  unsigned int& et, bool& egVecto, bool& activity) const {
174  throw cms::Exception("Not Implemented") << "CaloTPGTranscoderULUT::rctEGammaUncompress";
175 }
177  const EcalTrigTowerDetId& eid, const EcalTriggerPrimitiveSample& ec,
178  unsigned int& et) const {
179  throw cms::Exception("Not Implemented") << "CaloTPGTranscoderULUT::rctJetUncompress";
180 }
181 
182 bool CaloTPGTranscoderULUT::HTvalid(const int ieta, const int iphiin) const {
183  HcalTrigTowerDetId id(ieta, iphiin);
184  if (!theTopology) {
185  throw cms::Exception("CaloTPGTranscoderULUT") << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
186  }
187  return theTopology->validHT(id);
188 }
189 
191  if (!theTopology) {
192  throw cms::Exception("CaloTPGTranscoderULUT") << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
193  }
194  return theTopology->detId2denseIdHT(id);
195 }
196 
197 int CaloTPGTranscoderULUT::getOutputLUTId(const int ieta, const int iphiin) const {
198  if (!theTopology) {
199  throw cms::Exception("CaloTPGTranscoderULUT") << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
200  }
201  HcalTrigTowerDetId id(ieta, iphiin);
202  return theTopology->detId2denseIdHT(id);
203 }
204 
205 const std::vector<unsigned int>& CaloTPGTranscoderULUT::getCompressionLUT(const HcalTrigTowerDetId& id) const {
206  int itower = getOutputLUTId(id);
207  return outputLUT_[itower];
208 }
209 
210 void CaloTPGTranscoderULUT::setup(HcalLutMetadata const& lutMetadata, HcalTrigTowerGeometry const& theTrigTowerGeometry)
211 {
212  theTopology = lutMetadata.topo();
213  nominal_gain_ = lutMetadata.getNominalGain();
214  float rctlsb =lutMetadata.getRctLsb();
215  if (rctlsb != LSB_HBHE && rctlsb != LSB_HF)
216  throw cms::Exception("RCTLSB") << " value=" << rctlsb << " (should be " << LSB_HBHE
217  << " or " << LSB_HF << ")" << std::endl;
218  rctlsb_factor_ = rctlsb;
219 
220  if (compressionFile_.empty() && decompressionFile_.empty()) {
221  loadHCALCompress(lutMetadata,theTrigTowerGeometry);
222  }
223  else {
224  throw cms::Exception("Not Implemented") << "setup of CaloTPGTranscoderULUT from text files";
225  }
226 }
227 
int i
Definition: DBlmapReader.cc:9
std::vector< RCTdecompression > hcaluncomp_
std::vector< std::vector< LUT > > outputLUT_
uint8_t getOutputLutThreshold() const
unsigned int detId2denseIdHT(const DetId &id) const
return a linear packed id from HT
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
virtual const std::vector< unsigned int > & getCompressionLUT(const HcalTrigTowerDetId &id) const
uint8_t getLutGranularity() const
#define constexpr
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.
bool isHcalTrigTowerDetId() const
const HcalTopology * theTopology
std::vector< DetId > getAllChannels() const
T sqrt(T t)
Definition: SSEVec.h:18
float getNominalGain() const
virtual int getOutputLUTId(const HcalTrigTowerDetId &id) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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.
T min(T a, T b)
Definition: MathUtil.h:58
bool isHcalDetId() const
virtual bool HTvalid(const int ieta, const int iphi) const
void loadHCALCompress(HcalLutMetadata const &, HcalTrigTowerGeometry const &)
float getRctLsb() const
virtual void setup(HcalLutMetadata const &, HcalTrigTowerGeometry const &)
virtual double hcaletValue(const int &ieta, const int &compressedValue) const
static const unsigned int TPGMAX
susybsm::HSCParticleCollection hc
Definition: classes.h:25
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.
virtual HcalTriggerPrimitiveSample hcalCompress(const HcalTrigTowerDetId &id, unsigned int sample, bool fineGrain) const
Compression from linear samples+fine grain in the HTR.
const HcalTopology * topo() const
bool validHT(const HcalTrigTowerDetId &id) const
int firstHFTower(int version) const