CMS 3D CMS Logo

EcalUncalibRecHitProducerPortable.cc
Go to the documentation of this file.
15 
16 #include "DeclsForKernels.h"
18 
20 
22  public:
24  ~EcalUncalibRecHitProducerPortable() override = default;
26 
27  void acquire(device::Event const&, device::EventSetup const&) override;
28  void produce(device::Event&, device::EventSetup const&) override;
29 
30  private:
37 
38  // conditions tokens
41 
42  // configuration parameters
44 
47  };
48 
51 
52  desc.add<edm::InputTag>("digisLabelEB", edm::InputTag("ecalRawToDigiPortable", "ebDigis"));
53  desc.add<edm::InputTag>("digisLabelEE", edm::InputTag("ecalRawToDigiPortable", "eeDigis"));
54 
55  desc.add<std::string>("recHitsLabelEB", "EcalUncalibRecHitsEB");
56  desc.add<std::string>("recHitsLabelEE", "EcalUncalibRecHitsEE");
57 
58  desc.add<double>("EBtimeFitLimits_Lower", 0.2);
59  desc.add<double>("EBtimeFitLimits_Upper", 1.4);
60  desc.add<double>("EEtimeFitLimits_Lower", 0.2);
61  desc.add<double>("EEtimeFitLimits_Upper", 1.4);
62  desc.add<double>("EBtimeConstantTerm", .6);
63  desc.add<double>("EEtimeConstantTerm", 1.0);
64  desc.add<double>("EBtimeNconst", 28.5);
65  desc.add<double>("EEtimeNconst", 31.8);
66  desc.add<double>("outOfTimeThresholdGain12pEB", 5);
67  desc.add<double>("outOfTimeThresholdGain12mEB", 5);
68  desc.add<double>("outOfTimeThresholdGain61pEB", 5);
69  desc.add<double>("outOfTimeThresholdGain61mEB", 5);
70  desc.add<double>("outOfTimeThresholdGain12pEE", 1000);
71  desc.add<double>("outOfTimeThresholdGain12mEE", 1000);
72  desc.add<double>("outOfTimeThresholdGain61pEE", 1000);
73  desc.add<double>("outOfTimeThresholdGain61mEE", 1000);
74  desc.add<double>("amplitudeThresholdEB", 10);
75  desc.add<double>("amplitudeThresholdEE", 10);
76  desc.addUntracked<std::vector<uint32_t>>("kernelMinimizeThreads", {32, 1, 1});
77  desc.add<bool>("shouldRunTimingComputation", true);
78  confDesc.addWithDefaultLabel(desc);
79  }
80 
82  : digisTokenEB_{consumes(ps.getParameter<edm::InputTag>("digisLabelEB"))},
83  digisTokenEE_{consumes(ps.getParameter<edm::InputTag>("digisLabelEE"))},
84  uncalibRecHitsTokenEB_{produces(ps.getParameter<std::string>("recHitsLabelEB"))},
85  uncalibRecHitsTokenEE_{produces(ps.getParameter<std::string>("recHitsLabelEE"))},
86  multifitConditionsToken_{esConsumes()},
87  multifitParametersToken_{esConsumes()},
88  ebDigisSizeHostBuf_{cms::alpakatools::make_host_buffer<uint32_t>()},
89  eeDigisSizeHostBuf_{cms::alpakatools::make_host_buffer<uint32_t>()} {
90  // Workaround until the ProductID problem in issue https://github.com/cms-sw/cmssw/issues/44643 is fixed
91 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
92  producesTemporarily("edm::DeviceProduct<alpaka_cuda_async::EcalUncalibratedRecHitDeviceCollection>",
93  ps.getParameter<std::string>("recHitsLabelEB"));
94  producesTemporarily("edm::DeviceProduct<alpaka_cuda_async::EcalUncalibratedRecHitDeviceCollection>",
95  ps.getParameter<std::string>("recHitsLabelEE"));
96 #endif
97 
98  std::pair<double, double> EBtimeFitLimits, EEtimeFitLimits;
99  EBtimeFitLimits.first = ps.getParameter<double>("EBtimeFitLimits_Lower");
100  EBtimeFitLimits.second = ps.getParameter<double>("EBtimeFitLimits_Upper");
101  EEtimeFitLimits.first = ps.getParameter<double>("EEtimeFitLimits_Lower");
102  EEtimeFitLimits.second = ps.getParameter<double>("EEtimeFitLimits_Upper");
103 
104  auto EBtimeConstantTerm = ps.getParameter<double>("EBtimeConstantTerm");
105  auto EEtimeConstantTerm = ps.getParameter<double>("EEtimeConstantTerm");
106  auto EBtimeNconst = ps.getParameter<double>("EBtimeNconst");
107  auto EEtimeNconst = ps.getParameter<double>("EEtimeNconst");
108 
109  auto outOfTimeThreshG12pEB = ps.getParameter<double>("outOfTimeThresholdGain12pEB");
110  auto outOfTimeThreshG12mEB = ps.getParameter<double>("outOfTimeThresholdGain12mEB");
111  auto outOfTimeThreshG61pEB = ps.getParameter<double>("outOfTimeThresholdGain61pEB");
112  auto outOfTimeThreshG61mEB = ps.getParameter<double>("outOfTimeThresholdGain61mEB");
113  auto outOfTimeThreshG12pEE = ps.getParameter<double>("outOfTimeThresholdGain12pEE");
114  auto outOfTimeThreshG12mEE = ps.getParameter<double>("outOfTimeThresholdGain12mEE");
115  auto outOfTimeThreshG61pEE = ps.getParameter<double>("outOfTimeThresholdGain61pEE");
116  auto outOfTimeThreshG61mEE = ps.getParameter<double>("outOfTimeThresholdGain61mEE");
117  auto amplitudeThreshEB = ps.getParameter<double>("amplitudeThresholdEB");
118  auto amplitudeThreshEE = ps.getParameter<double>("amplitudeThresholdEE");
119 
120  // switch to run timing computation kernels
121  configParameters_.shouldRunTimingComputation = ps.getParameter<bool>("shouldRunTimingComputation");
122 
123  // minimize kernel launch conf
124  auto threadsMinimize = ps.getUntrackedParameter<std::vector<uint32_t>>("kernelMinimizeThreads");
125  configParameters_.kernelMinimizeThreads[0] = threadsMinimize[0];
126  configParameters_.kernelMinimizeThreads[1] = threadsMinimize[1];
127  configParameters_.kernelMinimizeThreads[2] = threadsMinimize[2];
128 
129  //
130  // configuration and physics parameters: done once
131  // assume there is a single device
132  // use sync copying
133  //
134 
135  // time fit parameters and limits
136  configParameters_.timeFitLimitsFirstEB = EBtimeFitLimits.first;
137  configParameters_.timeFitLimitsSecondEB = EBtimeFitLimits.second;
138  configParameters_.timeFitLimitsFirstEE = EEtimeFitLimits.first;
139  configParameters_.timeFitLimitsSecondEE = EEtimeFitLimits.second;
140 
141  // time constant terms
142  configParameters_.timeConstantTermEB = EBtimeConstantTerm;
143  configParameters_.timeConstantTermEE = EEtimeConstantTerm;
144 
145  // time N const
146  configParameters_.timeNconstEB = EBtimeNconst;
147  configParameters_.timeNconstEE = EEtimeNconst;
148 
149  // amplitude threshold for time flags
150  configParameters_.amplitudeThreshEB = amplitudeThreshEB;
151  configParameters_.amplitudeThreshEE = amplitudeThreshEE;
152 
153  // out of time thresholds gain-dependent
154  configParameters_.outOfTimeThreshG12pEB = outOfTimeThreshG12pEB;
155  configParameters_.outOfTimeThreshG12pEE = outOfTimeThreshG12pEE;
156  configParameters_.outOfTimeThreshG61pEB = outOfTimeThreshG61pEB;
157  configParameters_.outOfTimeThreshG61pEE = outOfTimeThreshG61pEE;
158  configParameters_.outOfTimeThreshG12mEB = outOfTimeThreshG12mEB;
159  configParameters_.outOfTimeThreshG12mEE = outOfTimeThreshG12mEE;
160  configParameters_.outOfTimeThreshG61mEB = outOfTimeThreshG61mEB;
161  configParameters_.outOfTimeThreshG61mEE = outOfTimeThreshG61mEE;
162  }
163 
165  auto& queue = event.queue();
166 
167  // get device collections from event
168  auto const& ebDigisDev = event.get(digisTokenEB_);
169  auto const& eeDigisDev = event.get(digisTokenEE_);
170 
171  // copy the actual numbers of digis in the collections to host
172  auto ebDigisSizeDevConstView =
173  cms::alpakatools::make_device_view<const uint32_t>(alpaka::getDev(queue), ebDigisDev.const_view().size());
174  auto eeDigisSizeDevConstView =
175  cms::alpakatools::make_device_view<const uint32_t>(alpaka::getDev(queue), eeDigisDev.const_view().size());
176  alpaka::memcpy(queue, ebDigisSizeHostBuf_, ebDigisSizeDevConstView);
177  alpaka::memcpy(queue, eeDigisSizeHostBuf_, eeDigisSizeDevConstView);
178  }
179 
181  auto& queue = event.queue();
182 
183  // get device collections from event
184  auto const& ebDigisDev = event.get(digisTokenEB_);
185  auto const& eeDigisDev = event.get(digisTokenEE_);
186 
187  // get the actual numbers of digis in the collections
188  auto const ebDigisSize = static_cast<int>(*ebDigisSizeHostBuf_.data());
189  auto const eeDigisSize = static_cast<int>(*eeDigisSizeHostBuf_.data());
190 
191  // output device collections
192  OutputProduct uncalibRecHitsDevEB{ebDigisSize, queue};
193  OutputProduct uncalibRecHitsDevEE{eeDigisSize, queue};
194  // reset the size scalar of the SoA
195  // memset takes an alpaka view that is created from the scalar in a view to the portable device collection
196  auto uncalibRecHitSizeViewEB =
197  cms::alpakatools::make_device_view<uint32_t>(alpaka::getDev(queue), uncalibRecHitsDevEB.view().size());
198  auto uncalibRecHitSizeViewEE =
199  cms::alpakatools::make_device_view<uint32_t>(alpaka::getDev(queue), uncalibRecHitsDevEE.view().size());
200  alpaka::memset(queue, uncalibRecHitSizeViewEB, 0);
201  alpaka::memset(queue, uncalibRecHitSizeViewEE, 0);
202 
203  // stop here if there are no digis
204  if (ebDigisSize + eeDigisSize > 0) {
205  // conditions
206  auto const& multifitConditionsDev = setup.getData(multifitConditionsToken_);
207  auto const& multifitParametersDev = setup.getData(multifitParametersToken_);
208 
209  //
210  // schedule algorithms
211  //
213  ebDigisDev,
214  eeDigisDev,
215  uncalibRecHitsDevEB,
216  uncalibRecHitsDevEE,
217  multifitConditionsDev,
218  multifitParametersDev,
220  }
221 
222  // put into the event
223  event.emplace(uncalibRecHitsTokenEB_, std::move(uncalibRecHitsDevEB));
224  event.emplace(uncalibRecHitsTokenEE_, std::move(uncalibRecHitsDevEE));
225  }
226 
227 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
228 
230 DEFINE_FWK_ALPAKA_MODULE(EcalUncalibRecHitProducerPortable);
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
PortableCollection< EcalUncalibratedRecHitSoA > EcalUncalibratedRecHitDeviceCollection
const device::ESGetToken< EcalMultifitConditionsDevice, EcalMultifitConditionsRcd > multifitConditionsToken_
void launchKernels(Queue &queue, InputProduct const &digisDevEB, InputProduct const &digisDevEE, OutputProduct &uncalibRecHitsDevEB, OutputProduct &uncalibRecHitsDevEE, EcalMultifitConditionsDevice const &conditionsDev, EcalMultifitParametersDevice const &paramsDev, ConfigurationParameters const &configParams)
typename detail::buffer_type< DevHost, T >::type host_buffer
Definition: memory.h:57
void acquire(device::Event const &, device::EventSetup const &) override
const device::ESGetToken< EcalMultifitParametersDevice, EcalMultifitParametersRcd > multifitParametersToken_
PortableCollection< EcalDigiSoA > EcalDigiDeviceCollection
#define DEFINE_FWK_ALPAKA_MODULE(name)
Definition: MakerMacros.h:16
void produce(device::Event &, device::EventSetup const &) override
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1