Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:22

0001 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0002 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESProducer.h"
0007 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ModuleFactory.h"
0008 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0009 #include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
0010 #include "HeterogeneousCore/CUDACore/interface/JobConfigurationGPURecord.h"
0011 #include "RecoParticleFlow/PFClusterProducer/interface/alpaka/PFClusterParamsDeviceCollection.h"
0012 
0013 #include <array>
0014 
0015 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0016 
0017   class PFClusterParamsESProducer : public ESProducer {
0018   public:
0019     PFClusterParamsESProducer(edm::ParameterSet const& iConfig) : ESProducer(iConfig) {
0020       constexpr static uint32_t kMaxDepth_barrel = 4;
0021       constexpr static uint32_t kMaxDepth_endcap = 7;
0022       product = std::make_shared<reco::PFClusterParamsHostCollection>(std::max(kMaxDepth_barrel, kMaxDepth_endcap),
0023                                                                       cms::alpakatools::host());
0024       auto view = product->view();
0025 
0026       // seedFinder
0027       auto const& sfConf = iConfig.getParameterSet("seedFinder");
0028       view.nNeigh() = sfConf.getParameter<int>("nNeighbours");
0029       auto const& seedFinderConfs = sfConf.getParameterSetVector("thresholdsByDetector");
0030       for (auto const& pset : seedFinderConfs) {
0031         auto const& det = pset.getParameter<std::string>("detector");
0032         auto seedPt2Threshold = std::pow(pset.getParameter<double>("seedingThresholdPt"), 2.);
0033         auto const& thresholds = pset.getParameter<std::vector<double>>("seedingThreshold");
0034         if (det == "HCAL_BARREL1") {
0035           if (thresholds.size() != kMaxDepth_barrel)
0036             throw cms::Exception("Configuration") << "Invalid size (" << thresholds.size() << " != " << kMaxDepth_barrel
0037                                                   << ") for \"\" vector of det = \"" << det << "\"";
0038           view.seedPt2ThresholdHB() = seedPt2Threshold;
0039           for (size_t idx = 0; idx < thresholds.size(); ++idx) {
0040             view.seedEThresholdHB_vec()[idx] = thresholds[idx];
0041           }
0042         } else if (det == "HCAL_ENDCAP") {
0043           if (thresholds.size() != kMaxDepth_endcap)
0044             throw cms::Exception("Configuration") << "Invalid size (" << thresholds.size() << " != " << kMaxDepth_endcap
0045                                                   << ") for \"\" vector of det = \"" << det << "\"";
0046           view.seedPt2ThresholdHE() = seedPt2Threshold;
0047           for (size_t idx = 0; idx < thresholds.size(); ++idx) {
0048             view.seedEThresholdHE_vec()[idx] = thresholds[idx];
0049           }
0050         } else {
0051           throw cms::Exception("Configuration") << "Unknown detector when parsing seedFinder: " << det;
0052         }
0053       }
0054 
0055       // initialClusteringStep
0056       auto const& initConf = iConfig.getParameterSet("initialClusteringStep");
0057       auto const& topoThresholdConf = initConf.getParameterSetVector("thresholdsByDetector");
0058       for (auto const& pset : topoThresholdConf) {
0059         auto const& det = pset.getParameter<std::string>("detector");
0060         auto const& thresholds = pset.getParameter<std::vector<double>>("gatheringThreshold");
0061         if (det == "HCAL_BARREL1") {
0062           if (thresholds.size() != kMaxDepth_barrel)
0063             throw cms::Exception("Configuration") << "Invalid size (" << thresholds.size() << " != " << kMaxDepth_barrel
0064                                                   << ") for \"\" vector of det = \"" << det << "\"";
0065           for (size_t idx = 0; idx < thresholds.size(); ++idx) {
0066             view.topoEThresholdHB_vec()[idx] = thresholds[idx];
0067           }
0068         } else if (det == "HCAL_ENDCAP") {
0069           if (thresholds.size() != kMaxDepth_endcap)
0070             throw cms::Exception("Configuration") << "Invalid size (" << thresholds.size() << " != " << kMaxDepth_endcap
0071                                                   << ") for \"\" vector of det = \"" << det << "\"";
0072           for (size_t idx = 0; idx < thresholds.size(); ++idx) {
0073             view.topoEThresholdHE_vec()[idx] = thresholds[idx];
0074           }
0075         } else {
0076           throw cms::Exception("Configuration") << "Unknown detector when parsing initClusteringStep: " << det;
0077         }
0078       }
0079 
0080       // pfClusterBuilder
0081       auto const& pfClusterPSet = iConfig.getParameterSet("pfClusterBuilder");
0082       view.showerSigma2() = std::pow(pfClusterPSet.getParameter<double>("showerSigma"), 2.);
0083       view.minFracToKeep() = pfClusterPSet.getParameter<double>("minFractionToKeep");
0084       view.minFracTot() = pfClusterPSet.getParameter<double>("minFracTot");
0085       view.maxIterations() = pfClusterPSet.getParameter<unsigned int>("maxIterations");
0086       view.excludeOtherSeeds() = pfClusterPSet.getParameter<bool>("excludeOtherSeeds");
0087       view.stoppingTolerance() = pfClusterPSet.getParameter<double>("stoppingTolerance");
0088       auto const& pcPSet = pfClusterPSet.getParameterSet("positionCalc");
0089       view.minFracInCalc() = pcPSet.getParameter<double>("minFractionInCalc");
0090       view.minAllowedNormalization() = pcPSet.getParameter<double>("minAllowedNormalization");
0091 
0092       auto const& recHitEnergyNormConf = pfClusterPSet.getParameterSetVector("recHitEnergyNorms");
0093       for (auto const& pset : recHitEnergyNormConf) {
0094         auto const& recHitNorms = pset.getParameter<std::vector<double>>("recHitEnergyNorm");
0095         auto const& det = pset.getParameter<std::string>("detector");
0096         if (det == "HCAL_BARREL1") {
0097           if (recHitNorms.size() != kMaxDepth_barrel)
0098             throw cms::Exception("Configuration")
0099                 << "Invalid size (" << recHitNorms.size() << " != " << kMaxDepth_barrel
0100                 << ") for \"\" vector of det = \"" << det << "\"";
0101           for (size_t idx = 0; idx < recHitNorms.size(); ++idx) {
0102             view.recHitEnergyNormInvHB_vec()[idx] = 1. / recHitNorms[idx];
0103           }
0104         } else if (det == "HCAL_ENDCAP") {
0105           if (recHitNorms.size() != kMaxDepth_endcap)
0106             throw cms::Exception("Configuration")
0107                 << "Invalid size (" << recHitNorms.size() << " != " << kMaxDepth_endcap
0108                 << ") for \"\" vector of det = \"" << det << "\"";
0109           for (size_t idx = 0; idx < recHitNorms.size(); ++idx) {
0110             view.recHitEnergyNormInvHE_vec()[idx] = 1. / recHitNorms[idx];
0111           }
0112         } else {
0113           throw cms::Exception("Configuration") << "Unknown detector when parsing recHitEnergyNorms: " << det;
0114         }
0115       }
0116 
0117       auto const& barrelTimeResConf = pfClusterPSet.getParameterSet("timeResolutionCalcBarrel");
0118       view.barrelTimeResConsts_corrTermLowE() = barrelTimeResConf.getParameter<double>("corrTermLowE");
0119       view.barrelTimeResConsts_threshLowE() = barrelTimeResConf.getParameter<double>("threshLowE");
0120       view.barrelTimeResConsts_noiseTerm() = barrelTimeResConf.getParameter<double>("noiseTerm");
0121       view.barrelTimeResConsts_constantTermLowE2() =
0122           std::pow(barrelTimeResConf.getParameter<double>("constantTermLowE"), 2.);
0123       view.barrelTimeResConsts_noiseTermLowE() = barrelTimeResConf.getParameter<double>("noiseTermLowE");
0124       view.barrelTimeResConsts_threshHighE() = barrelTimeResConf.getParameter<double>("threshHighE");
0125       view.barrelTimeResConsts_constantTerm2() = std::pow(barrelTimeResConf.getParameter<double>("constantTerm"), 2.);
0126       view.barrelTimeResConsts_resHighE2() =
0127           std::pow(view.barrelTimeResConsts_noiseTerm() / view.barrelTimeResConsts_threshHighE(), 2.) +
0128           view.barrelTimeResConsts_constantTerm2();
0129 
0130       auto const& endcapTimeResConf = pfClusterPSet.getParameterSet("timeResolutionCalcEndcap");
0131       view.endcapTimeResConsts_corrTermLowE() = endcapTimeResConf.getParameter<double>("corrTermLowE");
0132       view.endcapTimeResConsts_threshLowE() = endcapTimeResConf.getParameter<double>("threshLowE");
0133       view.endcapTimeResConsts_noiseTerm() = endcapTimeResConf.getParameter<double>("noiseTerm");
0134       view.endcapTimeResConsts_constantTermLowE2() =
0135           std::pow(endcapTimeResConf.getParameter<double>("constantTermLowE"), 2.);
0136       view.endcapTimeResConsts_noiseTermLowE() = endcapTimeResConf.getParameter<double>("noiseTermLowE");
0137       view.endcapTimeResConsts_threshHighE() = endcapTimeResConf.getParameter<double>("threshHighE");
0138       view.endcapTimeResConsts_constantTerm2() = std::pow(endcapTimeResConf.getParameter<double>("constantTerm"), 2.);
0139       view.endcapTimeResConsts_resHighE2() =
0140           std::pow(view.endcapTimeResConsts_noiseTerm() / view.endcapTimeResConsts_threshHighE(), 2.) +
0141           view.endcapTimeResConsts_constantTerm2();
0142 
0143       setWhatProduced(this);
0144     }
0145 
0146     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0147       edm::ParameterSetDescription psetDesc;
0148       {
0149         auto const psetName = "seedFinder";
0150         edm::ParameterSetDescription foo;
0151         foo.add<int>("nNeighbours", 4);
0152         {
0153           edm::ParameterSetDescription validator;
0154           validator.add<std::string>("detector", "");
0155           validator.add<std::vector<double>>("seedingThreshold", {});
0156           validator.add<double>("seedingThresholdPt", 0.);
0157           std::vector<edm::ParameterSet> vDefaults(2);
0158           vDefaults[0].addParameter<std::string>("detector", "HCAL_BARREL1");
0159           vDefaults[0].addParameter<std::vector<double>>("seedingThreshold", {0.125, 0.25, 0.35, 0.35});
0160           vDefaults[0].addParameter<double>("seedingThresholdPt", 0.);
0161           vDefaults[1].addParameter<std::string>("detector", "HCAL_ENDCAP");
0162           vDefaults[1].addParameter<std::vector<double>>("seedingThreshold",
0163                                                          {0.1375, 0.275, 0.275, 0.275, 0.275, 0.275, 0.275});
0164           vDefaults[1].addParameter<double>("seedingThresholdPt", 0.);
0165           foo.addVPSet("thresholdsByDetector", validator, vDefaults);
0166         }
0167         psetDesc.add(psetName, foo);
0168       }
0169       {
0170         auto const psetName = "initialClusteringStep";
0171         edm::ParameterSetDescription foo;
0172         {
0173           edm::ParameterSetDescription validator;
0174           validator.add<std::string>("detector", "");
0175           validator.add<std::vector<double>>("gatheringThreshold", {});
0176           std::vector<edm::ParameterSet> vDefaults(2);
0177           vDefaults[0].addParameter<std::string>("detector", "HCAL_BARREL1");
0178           vDefaults[0].addParameter<std::vector<double>>("gatheringThreshold", {0.1, 0.2, 0.3, 0.3});
0179           vDefaults[1].addParameter<std::string>("detector", "HCAL_ENDCAP");
0180           vDefaults[1].addParameter<std::vector<double>>("gatheringThreshold", {0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2});
0181           foo.addVPSet("thresholdsByDetector", validator, vDefaults);
0182         }
0183         psetDesc.add(psetName, foo);
0184       }
0185       {
0186         auto const psetName = "pfClusterBuilder";
0187         edm::ParameterSetDescription foo;
0188         foo.add<unsigned int>("maxIterations", 50);
0189         foo.add<double>("minFracTot", 1e-20);
0190         foo.add<double>("minFractionToKeep", 1e-7);
0191         foo.add<bool>("excludeOtherSeeds", true);
0192         foo.add<double>("showerSigma", 10.);
0193         foo.add<double>("stoppingTolerance", 1e-8);
0194         {
0195           edm::ParameterSetDescription validator;
0196           validator.add<std::string>("detector", "");
0197           validator.add<std::vector<double>>("recHitEnergyNorm", {});
0198           std::vector<edm::ParameterSet> vDefaults(2);
0199           vDefaults[0].addParameter<std::string>("detector", "HCAL_BARREL1");
0200           vDefaults[0].addParameter<std::vector<double>>("recHitEnergyNorm", {0.1, 0.2, 0.3, 0.3});
0201           vDefaults[1].addParameter<std::string>("detector", "HCAL_ENDCAP");
0202           vDefaults[1].addParameter<std::vector<double>>("recHitEnergyNorm", {0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2});
0203           foo.addVPSet("recHitEnergyNorms", validator, vDefaults);
0204         }
0205         {
0206           edm::ParameterSetDescription bar;
0207           bar.add<double>("minFractionInCalc", 1e-9);
0208           bar.add<double>("minAllowedNormalization", 1e-9);
0209           foo.add("positionCalc", bar);
0210         }
0211         {
0212           edm::ParameterSetDescription bar;
0213           bar.add<double>("corrTermLowE", 0.);
0214           bar.add<double>("threshLowE", 6.);
0215           bar.add<double>("noiseTerm", 21.86);
0216           bar.add<double>("constantTermLowE", 4.24);
0217           bar.add<double>("noiseTermLowE", 8.);
0218           bar.add<double>("threshHighE", 15.);
0219           bar.add<double>("constantTerm", 2.82);
0220           foo.add("timeResolutionCalcBarrel", bar);
0221         }
0222         {
0223           edm::ParameterSetDescription bar;
0224           bar.add<double>("corrTermLowE", 0.);
0225           bar.add<double>("threshLowE", 6.);
0226           bar.add<double>("noiseTerm", 21.86);
0227           bar.add<double>("constantTermLowE", 4.24);
0228           bar.add<double>("noiseTermLowE", 8.);
0229           bar.add<double>("threshHighE", 15.);
0230           bar.add<double>("constantTerm", 2.82);
0231           foo.add("timeResolutionCalcEndcap", bar);
0232         }
0233         psetDesc.add(psetName, foo);
0234       }
0235 
0236       descriptions.addWithDefaultLabel(psetDesc);
0237     }
0238 
0239     std::shared_ptr<reco::PFClusterParamsHostCollection> produce(JobConfigurationGPURecord const& iRecord) {
0240       return product;
0241     }
0242 
0243   private:
0244     std::shared_ptr<reco::PFClusterParamsHostCollection> product;
0245   };
0246 
0247 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0248 
0249 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(PFClusterParamsESProducer);