CMS 3D CMS Logo

HtrXmlPatternSet.cc
Go to the documentation of this file.
1 #include "HtrXmlPatternSet.h"
2 #include <cmath>
3 #include <iostream>
4 
6  for (int i = 0; i < SAMPLES; i++) {
7  fCReal[i] = 0;
8  fCCoded[i] = 0;
9  fCQuantized[i] = 0;
10  }
11  m_sample_pos = 0;
12 }
13 
14 void ChannelPattern::Fill_by_hand(const HcalElectronicsMap* emap, int pattern_number) {
15  for (int iSample = 0; iSample < SAMPLES; iSample++) {
16  fCCoded[iSample] = 0;
17  fCQuantized[iSample] = 0;
18  }
19 
20  int dcc9[NUM_CRATES];
21  int dcc19[NUM_CRATES];
22  for (int jCrate = 0; jCrate < NUM_CRATES; jCrate++) {
23  dcc9[jCrate] = -1;
24  dcc19[jCrate] = -1;
25  }
26 
27  int iCrate;
28  iCrate = 4;
29  dcc9[iCrate] = 700;
30  dcc19[iCrate] = 701;
31  iCrate = 0;
32  dcc9[iCrate] = 702;
33  dcc19[iCrate] = 703;
34  iCrate = 1;
35  dcc9[iCrate] = 704;
36  dcc19[iCrate] = 705;
37  iCrate = 5;
38  dcc9[iCrate] = 706;
39  dcc19[iCrate] = 707;
40  iCrate = 11;
41  dcc9[iCrate] = 708;
42  dcc19[iCrate] = 709;
43  iCrate = 15;
44  dcc9[iCrate] = 710;
45  dcc19[iCrate] = 711;
46  iCrate = 17;
47  dcc9[iCrate] = 712;
48  dcc19[iCrate] = 713;
49  iCrate = 14;
50  dcc9[iCrate] = 714;
51  dcc19[iCrate] = 715;
52  iCrate = 10;
53  dcc9[iCrate] = 716;
54  dcc19[iCrate] = 717;
55  iCrate = 2;
56  dcc9[iCrate] = 718;
57  dcc19[iCrate] = 719;
58  iCrate = 9;
59  dcc9[iCrate] = 720;
60  dcc19[iCrate] = 721;
61  iCrate = 12;
62  dcc9[iCrate] = 722;
63  dcc19[iCrate] = 723;
64  iCrate = 3;
65  dcc9[iCrate] = 724;
66  dcc19[iCrate] = 725;
67  iCrate = 7;
68  dcc9[iCrate] = 726;
69  dcc19[iCrate] = 727;
70  iCrate = 6;
71  dcc9[iCrate] = 728;
72  dcc19[iCrate] = 729;
73  iCrate = 13;
74  dcc9[iCrate] = 730;
75  dcc19[iCrate] = 731;
76 
77  int* dcc = nullptr;
78  int spigot = -100;
79  if (m_slot >= 2 && m_slot <= 8) {
80  spigot = 2 * m_slot - m_tb - 3;
81  dcc = dcc9;
82  } else if (m_slot >= 13 && m_slot <= 18) {
83  spigot = 2 * m_slot - m_tb - 25;
84  dcc = dcc19;
85  } else
86  return;
87 
88  int fiber_channel = (m_chan - 1) % 3;
89  int fiber = (m_chan - fiber_channel - 1) / 3 + 1;
90  int dcc_num = dcc[m_crate] - 700;
91 
92  HcalElectronicsId heid(fiber_channel, fiber, spigot, dcc_num);
93  heid.setHTR(m_crate, m_slot, m_tb);
94 
95  //if (heid.readoutVMECrateId()!=m_crate) std::cout << "crate: " << heid.readoutVMECrateId() << "; " << m_crate << std::endl;
96  //if (heid.htrSlot()!=m_slot) std::cout << "slot: " << heid.htrSlot() << "; " << m_slot << std::endl;
97  //if (heid.htrTopBottom()!=m_tb) std::cout << "tb: " << heid.htrTopBottom() << "; " << m_tb << std::endl;
98  //if (heid.htrChanId()!=m_chan) std::cout << "chan: " << heid.htrChanId() << "; " << m_chan << std::endl;
99  //
100  //if (heid.readoutVMECrateId()==14 && heid.htrTopBottom()==0 && heid.htrChanId()==3) {
101  // std::cout << heid.rawId() << " " << heid << std::endl;
102  //}
103 
104  try {
105  const HcalDetId hdid = emap->lookup(heid);
106 
107  int etaabs = hdid.ietaAbs();
108  int phi = hdid.iphi();
109  int side = hdid.zside();
110  int depth = hdid.depth();
111  int subdet = hdid.subdet();
112 
114  if (pattern_number == 1) {
115  if (m_crate == 2 || m_crate == 9 || m_crate == 12)
116  return;
117  //fill only one channel per half-crate
118  if (m_slot != 2 && m_slot != 13)
119  return;
120  if (m_tb != 0)
121  return;
122  if (m_chan != 5)
123  return;
124 
125  //put some data here
126  fCCoded[31] = 17;
127  }
129  if (pattern_number == 2) {
130  if (depth > 1)
131  return;
132  if (subdet == 4 && etaabs < 30)
133  return;
134 
135  if ((etaabs + 2) % 4 != 0)
136  return;
137  int i = (etaabs + 2) / 4;
138  if (i < 1 || i > 7)
139  return;
140 
141  if ((phi + 3) % 4 != 0)
142  return;
143  int j = (phi + 3) / 4;
144  if (j < 1 || j > 18)
145  return;
146 
147  //add one to BX?
148  if (side < 0)
149  fCCoded[phi + 10] = i;
150  if (side > 0)
151  fCCoded[phi + 10] = i + 16;
152  }
154  if (pattern_number == 3) {
155  if (depth > 1 || etaabs != 18 || side != 1 || phi != 32)
156  return;
157  std::cout << "hello" << std::endl;
158  //add one to BX?
159  if (side > 0)
160  fCCoded[15] = 20;
161  }
162 
163  } catch (...) {
164  return;
165  }
166 }
167 
169  //first fill with pedestal value (currently hard-coded to 0)
170  for (int samples = 0; samples < params->m_samples_per_event; samples++) {
171  int index = m_sample_pos + samples;
172  if (index >= SAMPLES)
173  continue;
174 
175  fCCoded[index] = 0;
176  fCQuantized[index] = 0;
177  }
178 
179  //now fill with actual samples
180  for (int samples = 0; samples < data->size(); samples++) {
181  int index = m_sample_pos + params->m_presamples_per_event - data->presamples() + samples;
182  if (index < m_sample_pos || index >= (m_sample_pos + params->m_samples_per_event) || index >= SAMPLES)
183  continue;
184 
185  fCCoded[index] = data->sample(samples).adc();
186  fCQuantized[index] = data->sample(samples).nominal_fC();
187  }
188 
189  m_sample_pos += params->m_samples_per_event;
190 }
191 
193  //first fill with pedestal value (currently hard-coded to 0)
194  for (int samples = 0; samples < params->m_samples_per_event; samples++) {
195  int index = m_sample_pos + samples;
196  if (index >= SAMPLES)
197  continue;
198 
199  fCCoded[index] = 0;
200  fCQuantized[index] = 0;
201  }
202 
203  //now fill with actual samples
204  for (int samples = 0; samples < data->size(); samples++) {
205  int index = m_sample_pos + params->m_presamples_per_event - data->presamples() + samples;
206  if (index < m_sample_pos || index >= (m_sample_pos + params->m_samples_per_event) || index >= SAMPLES)
207  continue;
208 
209  fCCoded[index] = data->sample(samples).adc();
210  fCQuantized[index] = data->sample(samples).nominal_fC();
211  }
212 
213  m_sample_pos += params->m_samples_per_event;
214 }
215 
217  //first fill with pedestal value (currently hard-coded to 0)
218  for (int samples = 0; samples < params->m_samples_per_event; samples++) {
219  int index = m_sample_pos + samples;
220  if (index >= SAMPLES)
221  continue;
222 
223  fCCoded[index] = 0;
224  fCQuantized[index] = 0;
225  }
226 
227  //now fill with actual samples
228  for (int samples = 0; samples < data->size(); samples++) {
229  int index = m_sample_pos + params->m_presamples_per_event - data->presamples() + samples;
230  if (index < m_sample_pos || index >= (m_sample_pos + params->m_samples_per_event) || index >= SAMPLES)
231  continue;
232 
233  fCCoded[index] = data->sample(samples).adc();
234  fCQuantized[index] = data->sample(samples).nominal_fC();
235  }
236 
237  m_sample_pos += params->m_samples_per_event;
238 }
239 
240 HalfHtrData::HalfHtrData(int crate, int slot, int tb) {
241  for (int i = 0; i < 24; i++)
242  m_patterns[i].setLoc(crate, slot, tb, i + 1);
243  m_crate = crate;
244  m_slot = slot;
245  m_tb = tb;
246  //these are set later with map data
247  m_dcc = 0;
248  m_spigot = 0;
249 }
250 
251 CrateData::CrateData(int crate, int slotsActive[ChannelPattern::NUM_SLOTS]) {
252  for (int slot = 0; slot < ChannelPattern::NUM_SLOTS; slot++) {
253  for (int tb = 0; tb < 2; tb++) {
254  if (slotsActive[slot])
255  m_slotsDoubled[slot][tb] = new HalfHtrData(crate, slot, tb);
256  else
257  m_slotsDoubled[slot][tb] = nullptr;
258  }
259  }
260 }
261 
263  for (int slot = 0; slot < ChannelPattern::NUM_SLOTS; slot++) {
264  for (int tb = 0; tb < 2; tb++) {
265  if (m_slotsDoubled[slot][tb])
266  delete m_slotsDoubled[slot][tb];
267  }
268  }
269 }
270 
272  if (slot >= 0 && slot < ChannelPattern::NUM_SLOTS && (tb == 0 || tb == 1))
273  return m_slotsDoubled[slot][tb];
274  else
275  return nullptr;
276 }
277 
279  int slotsActive[ChannelPattern::NUM_SLOTS]) {
280  for (int crate = 0; crate < ChannelPattern::NUM_CRATES; crate++) {
281  if (cratesActive[crate])
282  m_crates[crate] = new CrateData(crate, slotsActive);
283  else
284  m_crates[crate] = nullptr;
285  }
286 }
287 
289  for (int crate = 0; crate < ChannelPattern::NUM_CRATES; crate++) {
290  if (m_crates[crate])
291  delete m_crates[crate];
292  }
293 }
294 
296  if (crate >= 0 && crate < ChannelPattern::NUM_CRATES)
297  return m_crates[crate];
298  else
299  return nullptr;
300 }
constexpr void setHTR(int crate, int slot, int tb)
void Fill_by_hand(const HcalElectronicsMap *, int)
HalfHtrData * m_slotsDoubled[ChannelPattern::NUM_SLOTS][2]
constexpr int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:141
constexpr int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:148
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
std::vector< T >::const_iterator const_iterator
int fCCoded[SAMPLES]
static const int NUM_CRATES
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
void Fill(HtrXmlPatternToolParameters *params, HBHEDigiCollection::const_iterator data)
double fCQuantized[SAMPLES]
static const int SAMPLES
ChannelPattern m_patterns[24]
CrateData(int crate, int slotsActive[ChannelPattern::NUM_SLOTS])
static const int NUM_SLOTS
HalfHtrData(int crate, int slot, int tb)
HalfHtrData * getHalfHtrData(int slot, int one_two_tb)
CrateData * getCrate(int crate)
HtrXmlPatternSet(int cratesActive[ChannelPattern::NUM_CRATES], int slotsActive[ChannelPattern::NUM_SLOTS])
double fCReal[SAMPLES]
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
Readout chain identification for Hcal.
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
CrateData * m_crates[ChannelPattern::NUM_CRATES]
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164