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  std::pair<double, double> EBtimeFitLimits, EEtimeFitLimits;
91  EBtimeFitLimits.first = ps.getParameter<double>("EBtimeFitLimits_Lower");
92  EBtimeFitLimits.second = ps.getParameter<double>("EBtimeFitLimits_Upper");
93  EEtimeFitLimits.first = ps.getParameter<double>("EEtimeFitLimits_Lower");
94  EEtimeFitLimits.second = ps.getParameter<double>("EEtimeFitLimits_Upper");
95 
96  auto EBtimeConstantTerm = ps.getParameter<double>("EBtimeConstantTerm");
97  auto EEtimeConstantTerm = ps.getParameter<double>("EEtimeConstantTerm");
98  auto EBtimeNconst = ps.getParameter<double>("EBtimeNconst");
99  auto EEtimeNconst = ps.getParameter<double>("EEtimeNconst");
100 
101  auto outOfTimeThreshG12pEB = ps.getParameter<double>("outOfTimeThresholdGain12pEB");
102  auto outOfTimeThreshG12mEB = ps.getParameter<double>("outOfTimeThresholdGain12mEB");
103  auto outOfTimeThreshG61pEB = ps.getParameter<double>("outOfTimeThresholdGain61pEB");
104  auto outOfTimeThreshG61mEB = ps.getParameter<double>("outOfTimeThresholdGain61mEB");
105  auto outOfTimeThreshG12pEE = ps.getParameter<double>("outOfTimeThresholdGain12pEE");
106  auto outOfTimeThreshG12mEE = ps.getParameter<double>("outOfTimeThresholdGain12mEE");
107  auto outOfTimeThreshG61pEE = ps.getParameter<double>("outOfTimeThresholdGain61pEE");
108  auto outOfTimeThreshG61mEE = ps.getParameter<double>("outOfTimeThresholdGain61mEE");
109  auto amplitudeThreshEB = ps.getParameter<double>("amplitudeThresholdEB");
110  auto amplitudeThreshEE = ps.getParameter<double>("amplitudeThresholdEE");
111 
112  // switch to run timing computation kernels
113  configParameters_.shouldRunTimingComputation = ps.getParameter<bool>("shouldRunTimingComputation");
114 
115  // minimize kernel launch conf
116  auto threadsMinimize = ps.getUntrackedParameter<std::vector<uint32_t>>("kernelMinimizeThreads");
117  configParameters_.kernelMinimizeThreads[0] = threadsMinimize[0];
118  configParameters_.kernelMinimizeThreads[1] = threadsMinimize[1];
119  configParameters_.kernelMinimizeThreads[2] = threadsMinimize[2];
120 
121  //
122  // configuration and physics parameters: done once
123  // assume there is a single device
124  // use sync copying
125  //
126 
127  // time fit parameters and limits
128  configParameters_.timeFitLimitsFirstEB = EBtimeFitLimits.first;
129  configParameters_.timeFitLimitsSecondEB = EBtimeFitLimits.second;
130  configParameters_.timeFitLimitsFirstEE = EEtimeFitLimits.first;
131  configParameters_.timeFitLimitsSecondEE = EEtimeFitLimits.second;
132 
133  // time constant terms
134  configParameters_.timeConstantTermEB = EBtimeConstantTerm;
135  configParameters_.timeConstantTermEE = EEtimeConstantTerm;
136 
137  // time N const
138  configParameters_.timeNconstEB = EBtimeNconst;
139  configParameters_.timeNconstEE = EEtimeNconst;
140 
141  // amplitude threshold for time flags
142  configParameters_.amplitudeThreshEB = amplitudeThreshEB;
143  configParameters_.amplitudeThreshEE = amplitudeThreshEE;
144 
145  // out of time thresholds gain-dependent
146  configParameters_.outOfTimeThreshG12pEB = outOfTimeThreshG12pEB;
147  configParameters_.outOfTimeThreshG12pEE = outOfTimeThreshG12pEE;
148  configParameters_.outOfTimeThreshG61pEB = outOfTimeThreshG61pEB;
149  configParameters_.outOfTimeThreshG61pEE = outOfTimeThreshG61pEE;
150  configParameters_.outOfTimeThreshG12mEB = outOfTimeThreshG12mEB;
151  configParameters_.outOfTimeThreshG12mEE = outOfTimeThreshG12mEE;
152  configParameters_.outOfTimeThreshG61mEB = outOfTimeThreshG61mEB;
153  configParameters_.outOfTimeThreshG61mEE = outOfTimeThreshG61mEE;
154  }
155 
157  auto& queue = event.queue();
158 
159  // get device collections from event
160  auto const& ebDigisDev = event.get(digisTokenEB_);
161  auto const& eeDigisDev = event.get(digisTokenEE_);
162 
163  // copy the actual numbers of digis in the collections to host
164  auto ebDigisSizeDevConstView =
165  cms::alpakatools::make_device_view<const uint32_t>(queue, ebDigisDev.const_view().size());
166  auto eeDigisSizeDevConstView =
167  cms::alpakatools::make_device_view<const uint32_t>(queue, eeDigisDev.const_view().size());
168  alpaka::memcpy(queue, ebDigisSizeHostBuf_, ebDigisSizeDevConstView);
169  alpaka::memcpy(queue, eeDigisSizeHostBuf_, eeDigisSizeDevConstView);
170  }
171 
173  auto& queue = event.queue();
174 
175  // get device collections from event
176  auto const& ebDigisDev = event.get(digisTokenEB_);
177  auto const& eeDigisDev = event.get(digisTokenEE_);
178 
179  // get the actual numbers of digis in the collections
180  auto const ebDigisSize = static_cast<int>(*ebDigisSizeHostBuf_.data());
181  auto const eeDigisSize = static_cast<int>(*eeDigisSizeHostBuf_.data());
182 
183  // output device collections
184  OutputProduct uncalibRecHitsDevEB{ebDigisSize, queue};
185  OutputProduct uncalibRecHitsDevEE{eeDigisSize, queue};
186  // reset the size scalar of the SoA
187  // memset takes an alpaka view that is created from the scalar in a view to the portable device collection
188  auto uncalibRecHitSizeViewEB =
189  cms::alpakatools::make_device_view<uint32_t>(queue, uncalibRecHitsDevEB.view().size());
190  auto uncalibRecHitSizeViewEE =
191  cms::alpakatools::make_device_view<uint32_t>(queue, uncalibRecHitsDevEE.view().size());
192  alpaka::memset(queue, uncalibRecHitSizeViewEB, 0);
193  alpaka::memset(queue, uncalibRecHitSizeViewEE, 0);
194 
195  // stop here if there are no digis
196  if (ebDigisSize + eeDigisSize > 0) {
197  // conditions
198  auto const& multifitConditionsDev = setup.getData(multifitConditionsToken_);
199  auto const& multifitParametersDev = setup.getData(multifitParametersToken_);
200 
201  //
202  // schedule algorithms
203  //
205  ebDigisDev,
206  eeDigisDev,
207  uncalibRecHitsDevEB,
208  uncalibRecHitsDevEE,
209  multifitConditionsDev,
210  multifitParametersDev,
212  }
213 
214  // put into the event
215  event.emplace(uncalibRecHitsTokenEB_, std::move(uncalibRecHitsDevEB));
216  event.emplace(uncalibRecHitsTokenEE_, std::move(uncalibRecHitsDevEE));
217  }
218 
219 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
220 
222 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