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  size(0)
26 {
27  outputLUT_.clear();
28 }
29 
31 }
32 
34  HcalTrigTowerGeometry const& theTrigTowerGeometry) {
35  // Initialize analytical compression LUT's here
36  if (OUTPUT_LUT_SIZE != (unsigned int) 0x400)
37  edm::LogError("CaloTPGTranscoderULUT") << "Analytic compression expects 10-bit LUT; found LUT with " << OUTPUT_LUT_SIZE << " entries instead";
38 
39  if (!theTopology) {
40  throw cms::Exception("CaloTPGTranscoderULUT") << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
41  }
42 
43  std::array<unsigned int, OUTPUT_LUT_SIZE> analyticalLUT;
44  std::array<unsigned int, OUTPUT_LUT_SIZE> linearRctLUT;
45  std::array<unsigned int, OUTPUT_LUT_SIZE> linearNctLUT;
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  linearRctLUT[i] = min((unsigned int)(i/rct_factor_), TPGMAX - 1);
51  linearNctLUT[i] = min((unsigned int)(i/nct_factor_), TPGMAX - 1);
52  }
53 
54  std::vector<DetId> allChannels = lutMetadata.getAllChannels();
55 
56  for(std::vector<DetId>::iterator i=allChannels.begin(); i!=allChannels.end(); ++i){
57 
58  if (not HcalGenericDetId(*i).isHcalTrigTowerDetId()) {
59  if (not HcalGenericDetId(*i).isHcalDetId())
60  edm::LogWarning("CaloTPGTranscoderULUT") << "Encountered invalid HcalDetId " << HcalGenericDetId(*i);
61  continue;
62  }
63 
64  HcalTrigTowerDetId id(*i);
65  if(!theTopology->validHT(id)) continue;
66 
67 
68  unsigned int index = getOutputLUTId(id);
69 
70  if(index >= size){
71  size=index+1;
72  outputLUT_.resize(size);
73  hcaluncomp_.resize(size);
74  }
75 
76  const HcalLutMetadatum *meta = lutMetadata.getValues(id);
77  unsigned int threshold = meta->getOutputLutThreshold();
78 
79  int ieta=id.ieta();
80  int version=id.version();
81  bool isHBHE = (abs(ieta) < theTrigTowerGeometry.firstHFTower(version));
82 
83  for (unsigned int i = 0; i < threshold; ++i) outputLUT_[index].push_back(0);
84  for (unsigned int i = threshold; i < OUTPUT_LUT_SIZE; ++i){
85  LUT value = isHBHE ? analyticalLUT[i] :
86  (version==0?linearRctLUT[i]:linearNctLUT[i]);
87  outputLUT_[index].push_back(value);
88  }
89 
90  //now uncompression LUTs
91  hcaluncomp_[index].resize(TPGMAX);
92 
93  double eta_low = 0., eta_high = 0.;
94  theTrigTowerGeometry.towerEtaBounds(ieta,version,eta_low,eta_high);
95  double cosh_ieta = fabs(cosh((eta_low + eta_high)/2.));
96  double granularity = meta->getLutGranularity();
97 
98  if(isHBHE){
99  double factor = nominal_gain_ / cosh_ieta * granularity;
100  LUT tpg = outputLUT_[index][0];
101  int low = 0;
102  for (unsigned int i = 0; i < OUTPUT_LUT_SIZE; ++i){
103  if (outputLUT_[index][i] != tpg){
104  unsigned int mid = (low + i)/2;
105  hcaluncomp_[index][tpg] = (tpg == 0 ? low : factor * mid);
106  low = i;
107  tpg = outputLUT_[index][i];
108  }
109  }
110  hcaluncomp_[index][tpg] = factor * low;
111  }
112  else{
113  LUT tpg = outputLUT_[index][0];
114  hcaluncomp_[index][tpg]=0;
115  for (unsigned int i = 0; i < OUTPUT_LUT_SIZE; ++i){
116  if (outputLUT_[index][i] != tpg){
117  tpg = outputLUT_[index][i];
118  hcaluncomp_[index][tpg] = lsb_factor_ * i / (version==0?rct_factor_:nct_factor_);
119  }
120  }
121  }
122  }
123 }
124 
126  unsigned int itower = getOutputLUTId(id);
127 
128  if (sample >= OUTPUT_LUT_SIZE) {
129  throw cms::Exception("Out of Range") << "LUT has 1024 entries for " << itower << " but " << sample << " was requested.";
130  sample=OUTPUT_LUT_SIZE - 1;
131  }
132 
133  if(itower >= size){
134  throw cms::Exception("Out of Range") << "No decompression LUT found for " << id;
135  }
136 
137  return HcalTriggerPrimitiveSample(outputLUT_[itower][sample], fineGrain);
138 }
139 
140 double CaloTPGTranscoderULUT::hcaletValue(const int& ieta, const int& iphi, const int& version, const int& compET) const {
141  double etvalue = 0.;
142  int itower = getOutputLUTId(ieta,iphi, version);
143  if (itower < 0) {
144  edm::LogError("CaloTPGTranscoderULUT") << "No decompression LUT found for ieta, iphi = " << ieta << ", " << iphi;
145  } else if (compET < 0 || compET >= (int) TPGMAX) {
146  edm::LogError("CaloTPGTranscoderULUT") << "Compressed value out of range: eta, phi, cET = " << ieta << ", " << iphi << ", " << compET;
147  } else {
148  etvalue = hcaluncomp_[itower][compET];
149  }
150  return(etvalue);
151 }
152 
154  int compET = hc.compressedEt(); // to be within the range by the class
155  int itower = getOutputLUTId(hid);
156  double etvalue = hcaluncomp_[itower][compET];
157  return etvalue;
158 }
159 
161  throw cms::Exception("Not Implemented") << "CaloTPGTranscoderULUT::ecalCompress";
162 }
163 
165  const EcalTrigTowerDetId& eid, const EcalTriggerPrimitiveSample& ec,
166  unsigned int& et, bool& egVecto, bool& activity) const {
167  throw cms::Exception("Not Implemented") << "CaloTPGTranscoderULUT::rctEGammaUncompress";
168 }
170  const EcalTrigTowerDetId& eid, const EcalTriggerPrimitiveSample& ec,
171  unsigned int& et) const {
172  throw cms::Exception("Not Implemented") << "CaloTPGTranscoderULUT::rctJetUncompress";
173 }
174 
175 bool CaloTPGTranscoderULUT::HTvalid(const int ieta, const int iphiin, const int version) const {
176  HcalTrigTowerDetId id(ieta, iphiin);
177  id.setVersion(version);
178  if (!theTopology) {
179  throw cms::Exception("CaloTPGTranscoderULUT") << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
180  }
181  return theTopology->validHT(id);
182 }
183 
185  if (!theTopology) {
186  throw cms::Exception("CaloTPGTranscoderULUT") << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
187  }
188  return theTopology->detId2denseIdHT(id);
189 }
190 
191 int CaloTPGTranscoderULUT::getOutputLUTId(const int ieta, const int iphiin, const int version) const {
192  if (!theTopology) {
193  throw cms::Exception("CaloTPGTranscoderULUT") << "Topology not set! Use CaloTPGTranscoderULUT::setup(...) first!";
194  }
195  HcalTrigTowerDetId id(ieta, iphiin);
196  id.setVersion(version);
197  return theTopology->detId2denseIdHT(id);
198 }
199 
200 const std::vector<unsigned int>& CaloTPGTranscoderULUT::getCompressionLUT(const HcalTrigTowerDetId& id) const {
201  int itower = getOutputLUTId(id);
202  return outputLUT_[itower];
203 }
204 
205 void CaloTPGTranscoderULUT::setup(HcalLutMetadata const& lutMetadata, HcalTrigTowerGeometry const& theTrigTowerGeometry, int nctScaleShift, int rctScaleShift)
206 {
207  theTopology = lutMetadata.topo();
208  nominal_gain_ = lutMetadata.getNominalGain();
209  lsb_factor_ = lutMetadata.getRctLsb();
210 
211  rct_factor_ = lsb_factor_/(HcaluLUTTPGCoder::lsb_*(1<<rctScaleShift));
212  nct_factor_ = lsb_factor_/(HcaluLUTTPGCoder::lsb_*(1<<nctScaleShift));
213 
214  if (compressionFile_.empty() && decompressionFile_.empty()) {
215  loadHCALCompress(lutMetadata,theTrigTowerGeometry);
216  }
217  else {
218  throw cms::Exception("Not Implemented") << "setup of CaloTPGTranscoderULUT from text files";
219  }
220 }
virtual double hcaletValue(const int &ieta, const int &iphi, const int &version, const int &compressedValue) const
int i
Definition: DBlmapReader.cc:9
std::vector< RCTdecompression > hcaluncomp_
std::vector< std::vector< LUT > > outputLUT_
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
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
virtual const std::vector< unsigned int > & getCompressionLUT(const HcalTrigTowerDetId &id) const
uint8_t getLutGranularity() const
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.
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
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
void loadHCALCompress(HcalLutMetadata const &, HcalTrigTowerGeometry const &)
virtual void setup(HcalLutMetadata const &, HcalTrigTowerGeometry const &, int, int)
float getRctLsb() 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.
tuple size
Write out results.
const HcalTopology * topo() const
bool validHT(const HcalTrigTowerDetId &id) const
int firstHFTower(int version) const