File indexing completed on 2023-03-17 11:24:22
0001 #include "catch.hpp"
0002 #include "SimG4CMS/Calo/interface/HFShowerLibrary.h"
0003 #include "CLHEP/Units/GlobalPhysicalConstants.h"
0004 #include "FWCore/PluginManager/interface/PresenceFactory.h"
0005 #include "FWCore/PluginManager/interface/PluginManager.h"
0006 #include "FWCore/PluginManager/interface/standard.h"
0007 #include "CLHEP/Random/MixMaxRng.h"
0008 #include "Randomize.hh"
0009
0010 namespace {
0011 std::shared_ptr<edm::Presence> setupMessageLogger(bool iDoSetup) {
0012 if (not iDoSetup) {
0013 return std::shared_ptr<edm::Presence>();
0014 }
0015
0016 edmplugin::PluginManager::configure(edmplugin::standard::config());
0017
0018 try {
0019 return std::shared_ptr<edm::Presence>(
0020 edm::PresenceFactory::get()->makePresence("SingleThreadMSPresence").release());
0021 } catch (cms::Exception& e) {
0022 std::cerr << e.explainSelf() << std::endl;
0023 throw;
0024 }
0025 }
0026
0027 class SetRandomEngine {
0028 public:
0029 explicit SetRandomEngine(long iSeed) : m_current(iSeed), m_previous(G4Random::getTheEngine()) {
0030 G4Random::setTheEngine(&m_current);
0031 }
0032 ~SetRandomEngine() { G4Random::setTheEngine(m_previous); }
0033
0034 private:
0035 CLHEP::MixMaxRng m_current;
0036 decltype(G4Random::getTheEngine()) m_previous;
0037 };
0038
0039 }
0040
0041 bool operator==(HFShowerLibrary::Hit const& iLHS, HFShowerLibrary::Hit const& iRHS) {
0042 return iLHS.position == iRHS.position and iLHS.depth == iRHS.depth and iLHS.time == iRHS.time;
0043 }
0044
0045 namespace test_hffibre {
0046 HFFibre::Params defaultParams();
0047 }
0048
0049 TEST_CASE("test HFShowerLibrary", "[HFShowerLibrary]") {
0050
0051 static std::shared_ptr<edm::Presence> gobbleUpTheGoop = setupMessageLogger(false);
0052
0053 auto fibreParams = test_hffibre::defaultParams();
0054
0055
0056 HFShowerLibrary::Params params;
0057 params.probMax_ = 1.;
0058 params.backProb_ = 1.;
0059 params.dphi_ = 10 * deg;
0060 params.equalizeTimeShift_ = false;
0061 params.verbose_ = false;
0062 params.applyFidCut_ = true;
0063
0064 SECTION("v4 file") {
0065 HFShowerLibrary::FileParams fileParams;
0066 edm::FileInPath p("SimG4CMS/Calo/data/HFShowerLibrary_npmt_noatt_eta4_16en_v4.root");
0067 fileParams.fileName_ = p.fullPath();
0068 fileParams.emBranchName_ = "emParticles";
0069 fileParams.hadBranchName_ = "hadParticles";
0070 fileParams.branchEvInfo_ = "";
0071 fileParams.fileVersion_ = 0;
0072 fileParams.cacheBranches_ = false;
0073
0074 HFShowerLibrary showerLibrary(params, fileParams, fibreParams);
0075 SECTION("fillHits") {
0076 SECTION("non EM or Hadron") {
0077 SetRandomEngine guard(11);
0078 bool ok = false;
0079 auto hits = showerLibrary.fillHits({0, 0, 0}, {0, 0, 0}, 0, 0., ok, 1., 0.);
0080 REQUIRE(hits.empty());
0081 REQUIRE(not ok);
0082 }
0083 SECTION("photon within threshold") {
0084 SetRandomEngine guard(11);
0085 bool ok = false;
0086 auto hits = showerLibrary.fillHits(
0087 {-470.637, -618.696, 11150}, {0.000467326, -0.00804975, 0.999967}, 22, 2.2 * GeV, ok, 1., 0.);
0088 REQUIRE(ok);
0089 REQUIRE(hits.size() == 2);
0090 }
0091 SECTION("pion within threshold") {
0092 SetRandomEngine guard(11);
0093 bool ok = false;
0094 auto hits = showerLibrary.fillHits(
0095 {-470.637, -618.696, 11150}, {0.000467326, -0.00804975, 0.999967}, 211, 2.2 * GeV, ok, 1., 0.);
0096 REQUIRE(ok);
0097 REQUIRE(hits.size() == 2);
0098 }
0099 }
0100 SECTION("em cache") {
0101 std::vector<HFShowerLibrary::Hit> nonCached;
0102 {
0103 SetRandomEngine guard(11);
0104 bool ok = false;
0105 nonCached = showerLibrary.fillHits(
0106 {-470.637, -618.696, 11150}, {0.000467326, -0.00804975, 0.999967}, 22, 2.2 * GeV, ok, 1., 0.);
0107 }
0108 std::vector<HFShowerLibrary::Hit> cached;
0109 {
0110 auto newFileParams = fileParams;
0111 newFileParams.cacheBranches_ = true;
0112 HFShowerLibrary showerLibrary(params, newFileParams, fibreParams);
0113
0114 SetRandomEngine guard(11);
0115 bool ok = false;
0116 cached = showerLibrary.fillHits(
0117 {-470.637, -618.696, 11150}, {0.000467326, -0.00804975, 0.999967}, 22, 2.2 * GeV, ok, 1., 0.);
0118 }
0119 REQUIRE(nonCached == cached);
0120 }
0121
0122 SECTION("had cache") {
0123 std::vector<HFShowerLibrary::Hit> nonCached;
0124 {
0125 SetRandomEngine guard(11);
0126 bool ok = false;
0127 nonCached = showerLibrary.fillHits(
0128 {-470.637, -618.696, 11150}, {0.000467326, -0.00804975, 0.999967}, 211, 2.2 * GeV, ok, 1., 0.);
0129 }
0130 std::vector<HFShowerLibrary::Hit> cached;
0131 {
0132 auto newFileParams = fileParams;
0133 newFileParams.cacheBranches_ = true;
0134 HFShowerLibrary showerLibrary(params, newFileParams, fibreParams);
0135
0136 SetRandomEngine guard(11);
0137 bool ok = false;
0138 cached = showerLibrary.fillHits(
0139 {-470.637, -618.696, 11150}, {0.000467326, -0.00804975, 0.999967}, 211, 2.2 * GeV, ok, 1., 0.);
0140 }
0141 REQUIRE(nonCached == cached);
0142 }
0143 }
0144 SECTION("v3 file") {
0145 HFShowerLibrary::FileParams fileParams;
0146 edm::FileInPath p("SimG4CMS/Calo/data/HFShowerLibrary_oldpmt_noatt_eta4_16en_v3.root");
0147 fileParams.fileName_ = p.fullPath();
0148 fileParams.emBranchName_ = "emParticles";
0149 fileParams.hadBranchName_ = "hadParticles";
0150 fileParams.branchEvInfo_ = "";
0151 fileParams.fileVersion_ = 0;
0152 fileParams.cacheBranches_ = false;
0153
0154 HFShowerLibrary showerLibrary(params, fileParams, std::move(fibreParams));
0155 SECTION("fillHits") {
0156 SECTION("non EM or Hadron") {
0157 SetRandomEngine guard(11);
0158 bool ok = false;
0159 auto hits = showerLibrary.fillHits({0, 0, 0}, {0, 0, 0}, 0, 0., ok, 1., 0.);
0160 REQUIRE(hits.empty());
0161 REQUIRE(not ok);
0162 }
0163 SECTION("photon within threshold") {
0164 SetRandomEngine guard(11);
0165 bool ok = false;
0166 auto hits = showerLibrary.fillHits(
0167 {-470.637, -618.696, 11150}, {0.000467326, -0.00804975, 0.999967}, 22, 5.2 * GeV, ok, 1., 0.);
0168 REQUIRE(ok);
0169 REQUIRE(hits.size() == 1);
0170 }
0171 SECTION("pion within threshold") {
0172 SetRandomEngine guard(11);
0173 bool ok = false;
0174 auto hits = showerLibrary.fillHits(
0175 {-470.637, -618.696, 11150}, {0.000467326, -0.00804975, 0.999967}, 211, 5.2 * GeV, ok, 1., 0.);
0176 REQUIRE(ok);
0177 REQUIRE(hits.size() == 1);
0178 }
0179 }
0180 }
0181 SECTION("v6 file") {
0182 HFShowerLibrary::FileParams fileParams;
0183 edm::FileInPath p("SimG4CMS/Calo/data/HFShowerLibrary_run3_v6.root");
0184 fileParams.fileName_ = p.fullPath();
0185 fileParams.emBranchName_ = "emParticles";
0186 fileParams.hadBranchName_ = "hadParticles";
0187 fileParams.branchEvInfo_ = "";
0188 fileParams.fileVersion_ = 2;
0189 fileParams.cacheBranches_ = false;
0190
0191 params.equalizeTimeShift_ = true;
0192
0193 HFShowerLibrary showerLibrary(params, fileParams, std::move(fibreParams));
0194 SECTION("fillHits") {
0195 SECTION("non EM or Hadron") {
0196 SetRandomEngine guard(11);
0197 bool ok = false;
0198 auto hits = showerLibrary.fillHits({0, 0, 0}, {0, 0, 0}, 0, 0., ok, 1., 0.);
0199 REQUIRE(hits.empty());
0200 REQUIRE(not ok);
0201 }
0202 SECTION("photon within threshold") {
0203 SetRandomEngine guard(11);
0204 bool ok = false;
0205 auto hits = showerLibrary.fillHits(
0206 {-470.637, -618.696, 11150}, {0.000467326, -0.00804975, 0.999967}, 22, 2.2 * GeV, ok, 1., 0.);
0207 REQUIRE(ok);
0208 REQUIRE(hits.size() == 5);
0209 }
0210 SECTION("pion within threshold") {
0211 SetRandomEngine guard(11);
0212 bool ok = false;
0213 auto hits = showerLibrary.fillHits(
0214 {-470.637, -618.696, 11150}, {0.000467326, -0.00804975, 0.999967}, 211, 5.2 * GeV, ok, 1., 0.);
0215 REQUIRE(ok);
0216 REQUIRE(hits.size() == 2);
0217 }
0218 }
0219 }
0220 }