File indexing completed on 2024-04-06 12:31:31
0001 #include "FWCore/Framework/interface/ESProducer.h"
0002 #include "FWCore/Framework/interface/EventSetup.h"
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/Framework/interface/ModuleFactory.h"
0005
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ParameterSet/interface/EmptyGroupDescription.h"
0008
0009 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0010 #include "TrackingTools/GsfTracking/interface/GsfMaterialEffectsUpdator.h"
0011
0012 #include "TrackingTools/MaterialEffects/interface/MultipleScatteringUpdator.h"
0013 #include "TrackingTools/MaterialEffects/interface/EnergyLossUpdator.h"
0014 #include "TrackingTools/GsfTracking/interface/GsfMaterialEffectsAdapter.h"
0015 #include "TrackingTools/GsfTracking/interface/GsfMultipleScatteringUpdator.h"
0016 #include "TrackingTools/GsfTracking/interface/GsfBetheHeitlerUpdator.h"
0017 #include "TrackingTools/GsfTracking/interface/GsfCombinedMaterialEffectsUpdator.h"
0018
0019 #include <string>
0020 #include <memory>
0021 #include <optional>
0022
0023
0024
0025
0026
0027
0028
0029 class GsfMaterialEffectsESProducer : public edm::ESProducer {
0030 public:
0031 GsfMaterialEffectsESProducer(const edm::ParameterSet& p);
0032
0033 std::unique_ptr<GsfMaterialEffectsUpdator> produce(const TrackingComponentsRecord&);
0034
0035 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0036
0037 private:
0038 struct BetheHeitlerInit {
0039 BetheHeitlerInit(std::string iName, int iCorrection) : fileName(std::move(iName)), correction(iCorrection) {}
0040 std::string fileName;
0041 int correction;
0042 };
0043
0044 std::optional<BetheHeitlerInit> doInit(const edm::ParameterSet& p) {
0045 if (p.getParameter<std::string>("EnergyLossUpdator") != "GsfBetheHeitlerUpdator") {
0046 return std::optional<BetheHeitlerInit>();
0047 }
0048 return std::make_optional<BetheHeitlerInit>(p.getParameter<std::string>("BetheHeitlerParametrization"),
0049 p.getParameter<int>("BetheHeitlerCorrection"));
0050 }
0051
0052 std::optional<BetheHeitlerInit> betheHeitlerInit_;
0053 const double mass_;
0054 const bool useMultipleScattering_;
0055 };
0056
0057 using namespace edm;
0058
0059 GsfMaterialEffectsESProducer::GsfMaterialEffectsESProducer(const edm::ParameterSet& p)
0060 : betheHeitlerInit_(doInit(p)),
0061 mass_(p.getParameter<double>("Mass")),
0062 useMultipleScattering_(p.getParameter<std::string>("MultipleScatteringUpdator") == "GsfMultipleScatteringUpdator")
0063
0064 {
0065 std::string myname = p.getParameter<std::string>("ComponentName");
0066 setWhatProduced(this, myname);
0067 }
0068
0069 std::unique_ptr<GsfMaterialEffectsUpdator> GsfMaterialEffectsESProducer::produce(
0070 const TrackingComponentsRecord& iRecord) {
0071 std::unique_ptr<GsfMaterialEffectsUpdator> msUpdator;
0072 if (useMultipleScattering_) {
0073 msUpdator = std::make_unique<GsfMultipleScatteringUpdator>(mass_);
0074 } else {
0075 msUpdator = std::make_unique<GsfMaterialEffectsAdapter>(MultipleScatteringUpdator(mass_));
0076 }
0077
0078 std::unique_ptr<GsfMaterialEffectsUpdator> elUpdator;
0079 if (betheHeitlerInit_) {
0080 elUpdator = std::make_unique<GsfBetheHeitlerUpdator>(betheHeitlerInit_->fileName, betheHeitlerInit_->correction);
0081 } else {
0082 elUpdator = std::make_unique<GsfMaterialEffectsAdapter>(EnergyLossUpdator(mass_));
0083 }
0084
0085 auto updator = std::make_unique<GsfCombinedMaterialEffectsUpdator>(*msUpdator, *elUpdator);
0086
0087 return updator;
0088 }
0089
0090 void GsfMaterialEffectsESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0091 edm::ParameterSetDescription desc;
0092
0093 desc.add<std::string>("ComponentName");
0094 desc.add<double>("Mass");
0095 desc.add<std::string>("MultipleScatteringUpdator");
0096
0097 desc.ifValue(
0098 edm::ParameterDescription<std::string>("EnergyLossUpdator", "GsfBetheHeitlerUpdator", true),
0099 "GsfBetheHeitlerUpdator" >> (edm::ParameterDescription<std::string>("BetheHeitlerParametrization", true) and
0100 edm::ParameterDescription<int>("BetheHeitlerCorrection", true)) or
0101 "EnergyLossUpdator" >> edm::EmptyGroupDescription()
0102 );
0103 descriptions.addDefault(desc);
0104 }
0105
0106 DEFINE_FWK_EVENTSETUP_MODULE(GsfMaterialEffectsESProducer);