Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-21 01:40:01

0001 #ifndef RecoLocalCalo_EcalRecProducers_plugins_alpaka_EnergyComputationKernels_h
0002 #define RecoLocalCalo_EcalRecProducers_plugins_alpaka_EnergyComputationKernels_h
0003 
0004 #include <alpaka/alpaka.hpp>
0005 
0006 #include "CondFormats/EcalObjects/interface/EcalRecHitParameters.h"
0007 #include "CondFormats/EcalObjects/interface/alpaka/EcalRecHitConditionsDevice.h"
0008 #include "DataFormats/EcalRecHit/interface/alpaka/EcalRecHitDeviceCollection.h"
0009 #include "DataFormats/EcalRecHit/interface/alpaka/EcalUncalibratedRecHitDeviceCollection.h"
0010 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0011 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
0012 #include "DataFormats/Provenance/interface/Timestamp.h"
0013 #include "FWCore/Utilities/interface/HostDeviceConstant.h"
0014 
0015 #include "DeclsForKernels.h"
0016 #include "KernelHelpers.h"
0017 
0018 //#define DEBUG
0019 //#define ECAL_RECO_ALPAKA_DEBUG
0020 
0021 namespace ALPAKA_ACCELERATOR_NAMESPACE::ecal::rechit {
0022 
0023   HOST_DEVICE_CONSTANT float ip10[] = {1.e5f, 1.e4f, 1.e3f, 1.e2f, 1.e1f, 1.e0f, 1.e-1f, 1.e-2f, 1.e-3f, 1.e-4};
0024 
0025   ALPAKA_FN_ACC ALPAKA_FN_INLINE bool checkUncalibRecHitFlag(uint32_t const flags, EcalUncalibratedRecHit::Flags flag) {
0026     return flags & (0x1 << flag);
0027   }
0028 
0029   ALPAKA_FN_ACC ALPAKA_FN_INLINE void setFlag(uint32_t& flags, EcalRecHit::Flags flag) { flags |= (0x1 << flag); }
0030 
0031   ALPAKA_FN_ACC void makeRecHit(int const inputCh,
0032                                 uint32_t const* didCh,
0033                                 float const* amplitude,
0034                                 float const* amplitudeError,
0035                                 float const* jitter,
0036                                 uint32_t const* aux,
0037                                 float const* chi2_in,
0038                                 uint32_t const* flags_in,
0039                                 uint32_t* did,
0040                                 float* energy,
0041                                 float* time,
0042                                 uint32_t* flagBits,
0043                                 uint32_t* extra,
0044                                 EcalRecHitConditionsDevice::ConstView conditionsDev,
0045                                 EcalRecHitParameters const* parametersDev,
0046                                 // time, used for time dependent corrections
0047                                 edm::TimeValue_t const& eventTime,
0048                                 // configuration
0049                                 bool const isPhase2,
0050                                 bool const killDeadChannels,
0051                                 bool const recoverIsolatedChannels,
0052                                 bool const recoverVFE,
0053                                 bool const recoverFE,
0054                                 float const laserMIN,
0055                                 float const laserMAX,
0056                                 uint32_t flagmask);
0057 
0058   class KernelCreateEcalRechitPhase2 {
0059   public:
0060     ALPAKA_FN_ACC void operator()(Acc1D const& acc,
0061                                   EcalUncalibratedRecHitDeviceCollection::ConstView uncalibRecHits,
0062                                   EcalRecHitDeviceCollection::View recHits,
0063                                   EcalRecHitConditionsDevice::ConstView conditionsDev,
0064                                   EcalRecHitParameters const* parametersDev,
0065                                   // time, used for time dependent corrections
0066                                   edm::TimeValue_t const& eventTime,
0067                                   ConfigurationParameters const& configParams) const {
0068       auto const nchannels = uncalibRecHits.size();
0069 
0070       for (auto ch : cms::alpakatools::uniform_elements(acc, nchannels)) {
0071         // set the output collection size scalar
0072         if (ch == 0) {
0073           recHits.size() = nchannels;
0074         }
0075 
0076         makeRecHit(ch,
0077                    uncalibRecHits.id(),
0078                    uncalibRecHits.amplitude(),
0079                    uncalibRecHits.amplitudeError(),
0080                    uncalibRecHits.jitter(),
0081                    uncalibRecHits.aux(),
0082                    uncalibRecHits.chi2(),
0083                    uncalibRecHits.flags(),
0084                    recHits.id(),
0085                    recHits.energy(),
0086                    recHits.time(),
0087                    recHits.flagBits(),
0088                    recHits.extra(),
0089                    conditionsDev,
0090                    parametersDev,
0091                    eventTime,
0092                    true,
0093                    configParams.killDeadChannels,
0094                    configParams.recoverEBIsolatedChannels,
0095                    configParams.recoverEBVFE,
0096                    configParams.recoverEBFE,
0097                    configParams.EBLaserMIN,
0098                    configParams.EBLaserMAX,
0099                    configParams.flagmask);
0100 
0101       }  // end channel
0102     }
0103   };
0104 
0105   class KernelCreateEcalRechit {
0106   public:
0107     ALPAKA_FN_ACC void operator()(Acc1D const& acc,
0108                                   EcalUncalibratedRecHitDeviceCollection::ConstView ebUncalibRecHits,
0109                                   EcalUncalibratedRecHitDeviceCollection::ConstView eeUncalibRecHits,
0110                                   EcalRecHitDeviceCollection::View ebRecHits,
0111                                   EcalRecHitDeviceCollection::View eeRecHits,
0112                                   EcalRecHitConditionsDevice::ConstView conditionsDev,
0113                                   EcalRecHitParameters const* parametersDev,
0114                                   // time, used for time dependent corrections
0115                                   edm::TimeValue_t const& eventTime,
0116                                   ConfigurationParameters const& configParams) const {
0117       auto const nchannelsEB = ebUncalibRecHits.size();
0118       auto const nchannelsEE = eeUncalibRecHits.size();
0119       auto const nchannels = nchannelsEB + nchannelsEE;
0120 
0121       for (auto ch : cms::alpakatools::uniform_elements(acc, nchannels)) {
0122         // set the output collection size scalars
0123         if (ch == 0) {
0124           ebRecHits.size() = nchannelsEB;
0125         } else if (ch == nchannelsEB) {
0126           eeRecHits.size() = nchannelsEE;
0127         }
0128 
0129         bool const isEndcap = ch >= nchannelsEB;
0130         int const inputCh = isEndcap ? ch - nchannelsEB : ch;
0131 
0132         // inputs
0133         auto const* didCh = isEndcap ? eeUncalibRecHits.id() : ebUncalibRecHits.id();
0134         auto const* amplitude = isEndcap ? eeUncalibRecHits.amplitude() : ebUncalibRecHits.amplitude();
0135         auto const* amplitudeError = isEndcap ? eeUncalibRecHits.amplitudeError() : ebUncalibRecHits.amplitudeError();
0136         auto const* jitter = isEndcap ? eeUncalibRecHits.jitter() : ebUncalibRecHits.jitter();
0137         auto const* aux = isEndcap ? eeUncalibRecHits.aux() : ebUncalibRecHits.aux();
0138         auto const* chi2_in = isEndcap ? eeUncalibRecHits.chi2() : ebUncalibRecHits.chi2();
0139         auto const* flags_in = isEndcap ? eeUncalibRecHits.flags() : ebUncalibRecHits.flags();
0140 
0141         // outputs
0142         auto* did = isEndcap ? eeRecHits.id() : ebRecHits.id();
0143         auto* energy = isEndcap ? eeRecHits.energy() : ebRecHits.energy();
0144         auto* time = isEndcap ? eeRecHits.time() : ebRecHits.time();
0145         auto* flagBits = isEndcap ? eeRecHits.flagBits() : ebRecHits.flagBits();
0146         auto* extra = isEndcap ? eeRecHits.extra() : ebRecHits.extra();
0147 
0148         bool const recoverIsolatedChannels =
0149             isEndcap ? configParams.recoverEEIsolatedChannels : configParams.recoverEBIsolatedChannels;
0150         bool const recoverVFE = isEndcap ? configParams.recoverEEVFE : configParams.recoverEBVFE;
0151         bool const recoverFE = isEndcap ? configParams.recoverEEFE : configParams.recoverEBFE;
0152         float const laserMIN = isEndcap ? configParams.EELaserMIN : configParams.EBLaserMIN;
0153         float const laserMAX = isEndcap ? configParams.EELaserMAX : configParams.EBLaserMAX;
0154 
0155         makeRecHit(inputCh,
0156                    didCh,
0157                    amplitude,
0158                    amplitudeError,
0159                    jitter,
0160                    aux,
0161                    chi2_in,
0162                    flags_in,
0163                    did,
0164                    energy,
0165                    time,
0166                    flagBits,
0167                    extra,
0168                    conditionsDev,
0169                    parametersDev,
0170                    eventTime,
0171                    false,
0172                    configParams.killDeadChannels,
0173                    recoverIsolatedChannels,
0174                    recoverVFE,
0175                    recoverFE,
0176                    laserMIN,
0177                    laserMAX,
0178                    configParams.flagmask);
0179 
0180       }  // end channel
0181     }
0182   };
0183 
0184 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE::ecal::rechit
0185 
0186 #endif  // RecoLocalCalo_EcalRecProducers_plugins_alpaka_EnergyComputationKernels_h