10 #include "art/Framework/Core/EDAnalyzer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "art/Utilities/make_tool.h"
17 #include "art_root_io/TFileService.h"
19 #include "canvas/Utilities/InputTag.h"
20 #include "fhiclcpp/ParameterSet.h"
21 #include "messagefacility/MessageLogger/MessageLogger.h"
24 #include "nurandom/RandomUtils/NuRandomService.h"
25 #include "CLHEP/Random/JamesRandom.h"
26 #include "CLHEP/Random/RandFlat.h"
28 #include "nusimdata/SimulationBase/MCTruth.h"
29 #include "nusimdata/SimulationBase/MCFlux.h"
30 #include "nusimdata/SimulationBase/GTruth.h"
55 class MeVPrtlTestRayTrace;
73 void analyze(
const art::Event&
e)
override;
78 std::unique_ptr<evgen::ldm::IMesonGen>
fGenTool;
79 std::unique_ptr<evgen::ldm::IMeVPrtlFlux>
fFluxTool;
80 std::vector<std::unique_ptr<evgen::ldm::IRayTrace>>
fRayTools;
94 fGenTool = art::make_tool<IMesonGen>(
p.get<fhicl::ParameterSet>(
"MesonGen"));
95 fFluxTool = art::make_tool<IMeVPrtlFlux>(
p.get<fhicl::ParameterSet>(
"Flux"));
97 for (
auto const &rayconfig:
p.get<std::vector<fhicl::ParameterSet>>(
"RayTraces")) {
98 fRayTools.push_back(art::make_tool<IRayTrace>(rayconfig));
99 fBranchWeights.push_back(0);
102 fNCall =
p.get<
unsigned>(
"NCall", 10000);
105 art::ServiceHandle<art::TFileService>
tfs;
106 fTree = tfs->make<TTree>(
"testraytrace",
"testraytrace");
108 fTree->Branch(
"mevprtl", &fMeVPrtl);
109 for (
unsigned iray = 0; iray < fRayTools.size(); iray++) {
110 fTree->Branch((std::string(fRayTools[iray]->
Name()) +
"_wgt").c_str(), &fBranchWeights[iray]);
119 simb::MCFlux kaon = fGenTool->GetNext();
126 std::cout <<
"Flux is kaon (" << is_kaon <<
"). Weight: " << kaonp.
weight <<
". Produced with energy: " << kaonp.
mom.E()
127 <<
" M=" << kaonp.
mom.M() <<
" P=(" << kaonp.
mom.Px() <<
", " << kaonp.
mom.Py() <<
", " << kaonp.
mom.Pz() <<
") At: ("
128 << kaonp.
pos.X() <<
", " << kaonp.
pos.Y() <<
", " << kaonp.
pos.Z() <<
")" << std::endl;
136 success = fFluxTool->MakeFlux(kaon, flux, flux_weight);
137 if (!success)
continue;
139 std::cout <<
"New flux. E=" << flux.
mom.E() <<
" At: (" << flux.
pos.X() <<
", " << flux.
pos.Y() <<
", " << flux.
pos.Z() <<
")" << std::endl;
140 std::cout <<
"P=(" << flux.
mom.Px() <<
", " << flux.
mom.Py() <<
", " << flux.
mom.Pz() <<
")" << std::endl;
141 std::cout <<
"Flux weight: " << flux_weight << std::endl;
146 TVector3 det(0., 0., 0.);
147 double costh = flux.
kmom.Vect().Unit().Dot((det - flux.
pos.Vect()).Unit());
148 std::cout <<
"COSTH CRIT: " << costh_crit <<
" DETECTOR COSTH: " << costh << std::endl;
149 if (costh < costh_crit)
continue;
154 std::vector<double> weightsum(fRayTools.size(), 0.);
155 std::vector<double> time(fRayTools.size(), 0.);
156 for (
auto const &
r: fRayTools) {
157 std::array<TVector3, 2> intersection;
161 for (
unsigned icall = 0; icall < fNCall; icall++) {
162 success =
r->IntersectDetector(flux, intersection, ray_weight);
163 if (!success) ray_weight = 0.;
164 weightsum[iray] += ray_weight;
168 std::chrono::duration<double, std::milli> duration = t2 - t1;
169 time[iray] = duration.count();
175 for (
unsigned iray = 0; iray < fRayTools.size(); iray++) {
176 std::cout << fRayTools[iray]->Name() <<
" " << (time[iray] / fNCall) <<
" " << (weightsum[iray] / fNCall) << std::endl;
180 std::array<TVector3, 2> intersection;
182 for (
unsigned iray = 0; iray < fRayTools.size(); iray++) {
183 fBranchWeights[iray] = weightsum[iray] / fNCall;
MeVPrtlTestRayTrace(fhicl::ParameterSet const &p)
void analyze(const art::Event &e) override
~MeVPrtlTestRayTrace() noexcept
std::vector< std::unique_ptr< evgen::ldm::IRayTrace > > fRayTools
std::unique_ptr< evgen::ldm::IMesonGen > fGenTool
This is an interface for an art Tool which sources MCFlux objects for downstream processing and tabul...
MeVPrtlTestRayTrace & operator=(MeVPrtlTestRayTrace const &)=delete
BEGIN_PROLOG vertical distance to the surface Name
std::unique_ptr< evgen::ldm::IMeVPrtlFlux > fFluxTool
double minKinematicCosTheta(double parentM, double secM, double prtlM, double parentE)
This is an interface for an art Tool which turns MCFlux objects (which is a meson decay to neutrinos)...
art::ServiceHandle< art::TFileService > tfs
This provides an interface for an art tool which ray traces "Prtl" (massive) particles from their pro...
art framework interface to geometry description
BEGIN_PROLOG could also be cout
std::vector< double > fBranchWeights
This is an interface for an art Tool which decays "Prtl" inside a detector volume. It maps MeVPrtlFlux to MeVPrtlDecay.