CMS 3D CMS Logo

HcalConvertedPedestalWidthsGPU.cc
Go to the documentation of this file.
1 #include <cmath>
2 
6 
7 namespace {
8  float convert(
9  float const value, float const width, int const i, HcalQIECoder const& coder, HcalQIEShape const& shape) {
10  float const y = value;
11  float const x = width;
12  unsigned const x1 = static_cast<unsigned>(std::floor(y));
13  unsigned const x2 = static_cast<unsigned>(std::floor(y + 1.));
14  unsigned iun = static_cast<unsigned>(i);
15  float const y1 = coder.charge(shape, x1, iun);
16  float const y2 = coder.charge(shape, x2, iun);
17  return (y2 - y1) * x;
18  }
19 } // namespace
20 
21 // FIXME: add proper getters to conditions
23  HcalPedestalWidths const& pedestalWidths,
24  HcalQIEData const& qieData,
25  HcalQIETypes const& qieTypes)
26  : totalChannels_{pedestals.getAllContainers()[0].second.size() + pedestals.getAllContainers()[1].second.size()},
27  values_(totalChannels_ * 4) {
28 #ifdef HCAL_MAHI_CPUDEBUG
29  std::cout << "hello from converted pedestal widths" << std::endl;
30  std::cout << "pedestals HB values = " << pedestals.getAllContainers()[0].second.size()
31  << " HE values = " << pedestals.getAllContainers()[1].second.size() << std::endl;
32  std::cout << "qiedata HB values = " << qieData.getAllContainers()[0].second.size()
33  << " HE values = " << qieData.getAllContainers()[1].second.size() << std::endl;
34 #endif
35 
36  // retrieve all collections
37  auto const pedestalsAll = pedestals.getAllContainers();
38  auto const pedestalWidthsAll = pedestalWidths.getAllContainers();
39  auto const qieDataAll = qieData.getAllContainers();
40  auto const qieTypesAll = qieTypes.getAllContainers();
41 
42  // have to convert to fc if stored in adc
43  auto const unitIsADC = pedestals.isADC();
44 
45  // fill in barrel
46  auto const& pedestalBarrelValues = pedestalsAll[0].second;
47  auto const& pedestalWidthBarrelValues = pedestalWidthsAll[0].second;
48  auto const& qieDataBarrelValues = qieDataAll[0].second;
49  auto const& qieTypesBarrelValues = qieTypesAll[0].second;
50 
51 #ifdef HCAL_MAHI_CPUDEBUG
52  assert(pedestalWidthBarrelValues.size() == pedestalBarrelValues.size());
53  assert(pedestalBarrelValues.size() == qieDataBarrelValues.size());
54  assert(pedestalBarrelValues.size() == qieTypesBarrelValues.size());
55 #endif
56 
57  for (uint64_t i = 0; i < pedestalBarrelValues.size(); ++i) {
58  auto const& qieCoder = qieDataBarrelValues[i];
59  auto const qieType = qieTypesBarrelValues[i].getValue() > 1 ? 1 : 0;
60  auto const& qieShape = qieData.getShape(qieType);
61 
62  values_[i * 4] =
63  unitIsADC
64  ? convert(
65  pedestalBarrelValues[i].getValue(0), pedestalWidthBarrelValues[i].getWidth(0), 0, qieCoder, qieShape)
66  : pedestalWidthBarrelValues[i].getWidth(0);
67  values_[i * 4 + 1] =
68  unitIsADC
69  ? convert(
70  pedestalBarrelValues[i].getValue(1), pedestalWidthBarrelValues[i].getWidth(1), 1, qieCoder, qieShape)
71  : pedestalWidthBarrelValues[i].getWidth(1);
72  values_[i * 4 + 2] =
73  unitIsADC
74  ? convert(
75  pedestalBarrelValues[i].getValue(2), pedestalWidthBarrelValues[i].getWidth(2), 2, qieCoder, qieShape)
76  : pedestalWidthBarrelValues[i].getWidth(2);
77  values_[i * 4 + 3] =
78  unitIsADC
79  ? convert(
80  pedestalBarrelValues[i].getValue(3), pedestalWidthBarrelValues[i].getWidth(3), 3, qieCoder, qieShape)
81  : pedestalWidthBarrelValues[i].getWidth(3);
82  }
83 
84  // fill in endcap
85  auto const& pedestalEndcapValues = pedestalsAll[1].second;
86  auto const& pedestalWidthEndcapValues = pedestalWidthsAll[1].second;
87  auto const& qieDataEndcapValues = qieDataAll[1].second;
88  auto const& qieTypesEndcapValues = qieTypesAll[1].second;
89 
90 #ifdef HCAL_MAHI_CPUDEBUG
91  assert(pedestalWidthEndcapValues.size() == pedestalEndcapValues.size());
92  assert(pedestalEndcapValues.size() == qieDataEndcapValues.size());
93  assert(pedestalEndcapValues.size() == qieTypesEndcapValues.size());
94 #endif
95 
96  auto const offset = pedestalWidthBarrelValues.size();
97  for (uint64_t i = 0; i < pedestalEndcapValues.size(); ++i) {
98  auto const& qieCoder = qieDataEndcapValues[i];
99  auto const qieType = qieTypesEndcapValues[i].getValue() > 1 ? 1 : 0;
100  auto const& qieShape = qieData.getShape(qieType);
101  auto const off = offset + i;
102 
103  values_[off * 4] =
104  unitIsADC
105  ? convert(
106  pedestalEndcapValues[i].getValue(0), pedestalWidthEndcapValues[i].getWidth(0), 0, qieCoder, qieShape)
107  : pedestalWidthEndcapValues[i].getWidth(0);
108  values_[off * 4 + 1] =
109  unitIsADC
110  ? convert(
111  pedestalEndcapValues[i].getValue(1), pedestalWidthEndcapValues[i].getWidth(1), 1, qieCoder, qieShape)
112  : pedestalWidthEndcapValues[i].getWidth(1);
113  values_[off * 4 + 2] =
114  unitIsADC
115  ? convert(
116  pedestalEndcapValues[i].getValue(2), pedestalWidthEndcapValues[i].getWidth(2), 2, qieCoder, qieShape)
117  : pedestalWidthEndcapValues[i].getWidth(2);
118  values_[off * 4 + 3] =
119  unitIsADC
120  ? convert(
121  pedestalEndcapValues[i].getValue(3), pedestalWidthEndcapValues[i].getWidth(3), 3, qieCoder, qieShape)
122  : pedestalWidthEndcapValues[i].getWidth(3);
123 
124 #ifdef HCAL_MAHI_CPUDEBUG
125  if (pedestalEndcapValues[i].rawId() == DETID_TO_DEBUG) {
126  for (int i = 0; i < 4; i++)
127  printf("pedestalWidth(%d) = %f original pedestalWidth(%d) = %f\n",
128  i,
129  values_[off * 4 + i],
130  i,
131  pedestalWidthEndcapValues[i].getWidth(3));
132  }
133 #endif
134  }
135 }
136 
138  auto const& product = product_.dataForCurrentDeviceAsync(
139  stream, [this](HcalConvertedPedestalWidthsGPU::Product& product, cudaStream_t stream) {
140  // allocate
141  product.values = cms::cuda::make_device_unique<float[]>(values_.size(), stream);
142 
143  // transfer
145  });
146 
147  return product;
148 }
149 
ApeEstimator_cff.width
width
Definition: ApeEstimator_cff.py:24
mps_fire.i
i
Definition: mps_fire.py:428
HcalConvertedPedestalWidthsGPU::Product::values
edm::propagate_const_array< cms::cuda::device::unique_ptr< float[]> > values
Definition: HcalConvertedPedestalWidthsGPU.h:19
HcalQIECoder::charge
float charge(const HcalQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -> fC conversion.
Definition: HcalQIECoder.cc:20
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
gather_cfg.cout
cout
Definition: gather_cfg.py:144
typelookup.h
cms::cuda::assert
assert(be >=bs)
HcalConvertedPedestalWidthsGPU::product_
cms::cuda::ESProduct< Product > product_
Definition: HcalConvertedPedestalWidthsGPU.h:39
HcalPedestalWidths
Definition: HcalPedestalWidths.h:17
HcalPedestals
Definition: HcalPedestals.h:20
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
HcalConvertedPedestalWidthsGPU::values_
std::vector< float, cms::cuda::HostAllocator< float > > values_
Definition: HcalConvertedPedestalWidthsGPU.h:37
HcalConvertedPedestalWidthsGPU::Product
Definition: HcalConvertedPedestalWidthsGPU.h:18
testProducerWithPsetDescEmpty_cfi.y2
y2
Definition: testProducerWithPsetDescEmpty_cfi.py:30
fileCollector.convert
def convert(infile, ofile)
Definition: fileCollector.py:47
HcalConvertedPedestalWidthsGPU::HcalConvertedPedestalWidthsGPU
HcalConvertedPedestalWidthsGPU(HcalPedestals const &, HcalPedestalWidths const &, HcalQIEData const &, HcalQIETypes const &)
Definition: HcalConvertedPedestalWidthsGPU.cc:22
reco::JetExtendedAssociation::getValue
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
Definition: JetExtendedAssociation.cc:50
HcalConvertedPedestalWidthsGPU
Definition: HcalConvertedPedestalWidthsGPU.h:16
value
Definition: value.py:1
copyAsync.h
HcalCondObjectContainer::getAllContainers
const tAllContWithNames getAllContainers() const
Definition: HcalCondObjectContainer.h:81
HcalQIETypes
Definition: HcalQIETypes.h:17
TYPELOOKUP_DATA_REG
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:102
HcalQIEData
Definition: HcalQIEData.h:24
HcalQIECoder
Definition: HcalQIECoder.h:20
HcalConvertedPedestalWidthsGPU::getProduct
Product const & getProduct(cudaStream_t) const
Definition: HcalConvertedPedestalWidthsGPU.cc:137
relativeConstraints.value
value
Definition: relativeConstraints.py:53
genVertex_cff.x
x
Definition: genVertex_cff.py:12
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
HcalQIEShape
Definition: HcalQIEShape.h:17
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
HcalConvertedPedestalWidthsGPU.h
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
cms::cuda::copyAsync
void copyAsync(device::unique_ptr< T > &dst, const host::unique_ptr< T > &src, cudaStream_t stream)
Definition: copyAsync.h:20