CMS 3D CMS Logo

EcalEBPhase2TimeReconstructor.cc
Go to the documentation of this file.
7 #include <iostream>
8 
10  : debug_(debug), inputsAlreadyIn_(0), shift_(maxSamplesUsed_) {}
11 
13 
15  if (input > 0X7FFF) {
16  edm::LogError("EcalEBPhase2TimeReconstructor::setInput") << "ERROR IN INPUT OF TIME FILTER" << std::endl;
17  return -1;
18  }
20  if (debug_)
21  LogDebug("") << " EcalEBPhase2TimeReconstructor::setInput inputsAlreadyIn_<5 input " << input << std::endl;
22 
25  } else {
26  for (int i = 0; i < (maxSamplesUsed_ - 1); i++) {
27  buffer_[i] = buffer_[i + 1];
28  if (debug_)
29  LogDebug("") << " EcalEBPhase2TimeReconstructor::setInput inputsAlreadyIn buffer " << buffer_[i] << std::endl;
30  }
33  }
34  return 1;
35 }
36 
37 void EcalEBPhase2TimeReconstructor::process(std::vector<int> &addout,
38  std::vector<int> &ampRecoOutput,
39  std::vector<int64_t> &output) {
40  inputsAlreadyIn_ = 0;
41  for (unsigned int i = 0; i < maxSamplesUsed_; i++) {
42  buffer_[i] = 0;
43  }
44 
45  //Taking in the results of the amplitude reconstruction
46  //Bit shifting them for use as index of invAmpAr_ lookup table
47  // move input amplitude (13 bits) to 9 bits to use as array index
48 
49  ampIn_[0] = ampRecoOutput[0] >> 4;
50  ampIn_[1] = ampRecoOutput[1] >> 4;
51 
52  for (unsigned int i = 0; i < addout.size(); i++) {
53  setInput(addout[i]);
54 
55  if (debug_) {
56  LogDebug("") << " EcalEBPhase2TimeReconstructor::process(std::vector<int> buffer_ " << std::endl;
57 
58  for (unsigned int j = 0; j < maxSamplesUsed_; j++) {
59  LogDebug("") << " buffer_ " << buffer_[j];
60  }
61  LogDebug("") << " " << std::endl;
62  }
63 
64  if (i == (maxSamplesUsed_ - 1)) {
65  if (debug_)
66  LogDebug("") << " EcalEBPhase2TimeReconstructor::process(std::vector<int>) i = 11 " << std::endl;
67  process();
68  if (debug_)
69  LogDebug("") << " EcalEBPhase2TimeReconstructor::process(std::vector<int>) after process() "
70  << processedOutput_ << std::endl;
72  if (debug_)
73  LogDebug("") << " EcalEBPhase2TimeReconstructor::process(std::vector<int>) after setting the output "
74  << output[0] << std::endl;
75  } else if (i == (ecalPh2::sampleSize - 1)) {
76  if (debug_)
77  LogDebug("") << " EcalEBPhase2TimeReconstructor::process(std::vector<int>) i = 15 " << std::endl;
78  process();
80  }
81  }
82 
83  return;
84 }
85 
87  //UB FIXME: 5
88  processedOutput_ = 0;
89  if (inputsAlreadyIn_ < 12)
90  return;
91  int64_t output = 0;
92  for (int i = 0; i < 12; i++) {
93  output += (weights_[i] * buffer_[i]);
94  if (debug_)
95  LogDebug("") << " TimeFilter buffer " << buffer_[i] << " weight " << weights_[i] << " output " << output
96  << std::endl;
97  }
98  output = output >> shift_;
99  if (debug_)
100  LogDebug("") << " TimeFilter local output " << output << std::endl;
101  //Dividing output by the result of the amplitude reconstruction via an approximation using the invAmpAr lookup table
102  int ampInd = 0;
103  if (debug_)
104  LogDebug("") << " inputsAlreadyIn_ " << inputsAlreadyIn_ << std::endl;
105  if (inputsAlreadyIn_ > 12) {
106  ampInd = 1;
107  }
108 
109  if (debug_)
110  LogDebug("") << " Begininning Final TimeFilter Calculation" << std::endl;
111 
112  int64_t tmpOutput = output * invAmpAr_[ampIn_[ampInd]];
113  if (debug_)
114  LogDebug("") << " output*tmpInvAmpAr " << tmpOutput << std::endl;
115 
116  output = tmpOutput >> 20;
117  if (debug_)
118  LogDebug("") << " output after bit shift " << output << std::endl;
119 
120  if (output < -1024)
121  output = -1023;
122  else if (output > 1024)
123  output = 1023;
124  if (debug_)
125  LogDebug("") << " output after if/else " << output << std::endl;
127 
128  if (debug_)
129  LogDebug("") << " TimeFilter final output " << processedOutput_ << std::endl;
130 }
131 
133  const EcalEBPhase2TPGTimeWeightIdMap *ecaltpgWeightMap,
134  const EcalTPGWeightGroup *ecaltpgWeightGroup) {
135  uint32_t params_[12];
136  const EcalTPGGroups::EcalTPGGroupsMap &groupmap = ecaltpgWeightGroup->getMap();
137  if (debug_)
138  LogDebug("") << " EcalEBPhase2TimeReconstructor::setParameters groupmap size " << groupmap.size() << std::endl;
139  EcalTPGGroups::EcalTPGGroupsMapItr it = groupmap.find(raw);
140  if (it != groupmap.end()) {
141  uint32_t weightid = (*it).second;
142  const EcalEBPhase2TPGTimeWeightIdMap::EcalEBPhase2TPGTimeWeightMap &weightmap = ecaltpgWeightMap->getMap();
144 
145  (*itw).second.getValues(params_[0],
146  params_[1],
147  params_[2],
148  params_[3],
149  params_[4],
150  params_[5],
151  params_[6],
152  params_[7],
153  params_[8],
154  params_[9],
155  params_[10],
156  params_[11]);
157 
158  if (debug_)
159  LogDebug("") << " EcalEBPhase2TimeReconstructor::setParameters time weights after the map " << params_[0] << " "
160  << params_[1] << " " << params_[2] << " " << params_[3] << " " << params_[4] << " " << params_[5]
161  << " " << params_[6] << " " << params_[7] << " " << params_[8] << " " << params_[9] << " "
162  << params_[10] << " " << params_[11] << std::endl;
163 
164  // we have to transform negative coded in 16 bits into negative coded in 32 bits
165  // maybe this should go into the getValue method??
166 
167  for (int i = 0; i < 12; ++i) {
168  weights_[i] = (params_[i] & 0x8000) ? (int)(params_[i] | 0xffff8000) : (int)(params_[i]);
169  }
170 
171  } else
172  edm::LogWarning("EcalTPG")
173  << " EcalEBPhase2TimeReconstructor::setParameters could not find EcalTPGGroupsMap entry for " << raw;
174 }
std::map< uint32_t, uint32_t >::const_iterator EcalTPGGroupsMapItr
Definition: EcalTPGGroups.h:20
const EcalEBPhase2TPGTimeWeightMap & getMap() const
std::map< uint32_t, EcalEBPhase2TPGTimeWeights > EcalEBPhase2TPGTimeWeightMap
const EcalTPGGroupsMap & getMap() const
Definition: EcalTPGGroups.h:25
Log< level::Error, false > LogError
static std::string const input
Definition: EdmProvDump.cc:50
static constexpr unsigned int sampleSize
Definition: EcalConstants.h:36
#define debug
Definition: HDRShower.cc:19
Definition: output.py:1
Log< level::Warning, false > LogWarning
void setParameters(uint32_t raw, const EcalEBPhase2TPGTimeWeightIdMap *ecaltpgTimeWeightMap, const EcalTPGWeightGroup *ecaltpgWeightGroup)
std::map< uint32_t, uint32_t > EcalTPGGroupsMap
Definition: EcalTPGGroups.h:19
std::map< uint32_t, EcalEBPhase2TPGTimeWeights >::const_iterator EcalEBPhase2TPGTimeWeightMapItr
#define LogDebug(id)