44 #include "Framework/Algorithm/AlgFactory.h" 45 #include "Framework/EventGen/EventRecord.h" 46 #include "Framework/EventGen/EventRecordVisitorI.h" 47 #include "Framework/GHEP/GHepParticle.h" 48 #include "Framework/ParticleData/PDGLibrary.h" 49 #include "Framework/Utils/AppInit.h" 50 #include "Physics/NNBarOscillation/NNBarOscMode.h" 66 #include "CLHEP/Random/RandFlat.h" 95 const genie::EventRecordVisitorI*
mcgen;
107 string sname =
"genie::EventGenerator";
109 string sconfig =
"NNBarOsc";
113 genie::PDGLibrary::Instance();
115 genie::AlgFactory* algf = genie::AlgFactory::Instance();
116 mcgen =
dynamic_cast<const genie::EventRecordVisitorI*
>(algf->GetAlgorithm(sname, sconfig));
119 <<
"Couldn't instantiate the neutron-antineutron oscillation generator";
121 int fDecayMode = p.get<
int>(
"DecayMode");
124 produces<std::vector<simb::MCTruth>>();
125 produces<sumdata::RunData, art::InRun>();
128 genie::utils::app_init::RandGen(seed);
134 genie::EventRecord*
event =
new genie::EventRecord;
137 genie::Interaction*
interaction = genie::Interaction::NOsc(target, decay);
138 event->AttachSummary(interaction);
150 std::unique_ptr<std::vector<simb::MCTruth>> truthcol(
new std::vector<simb::MCTruth>);
163 if (minx > tpc.MinX()) minx = tpc.MinX();
164 if (maxx < tpc.MaxX()) maxx = tpc.MaxX();
165 if (miny > tpc.MinY()) miny = tpc.MinY();
166 if (maxy < tpc.MaxY()) maxy = tpc.MaxY();
167 if (minz > tpc.MinZ()) minz = tpc.MinZ();
168 if (maxz < tpc.MaxZ()) maxz = tpc.MaxZ();
172 double X0 =
flatDist.fire(minx, maxx);
173 double Y0 =
flatDist.fire(miny, maxy);
174 double Z0 =
flatDist.fire(minz, maxz);
176 TIter partitr(
event);
177 genie::GHepParticle*
part = 0;
182 std::string primary(
"primary");
184 while ((part = dynamic_cast<genie::GHepParticle*>(partitr.Next()))) {
187 trackid, part->Pdg(), primary, part->FirstMother(), part->Mass(), part->Status());
189 TLorentzVector pos(X0, Y0, Z0, 0);
190 TLorentzVector mom(part->Px(), part->Py(), part->Pz(), part->E());
191 tpart.AddTrajectoryPoint(pos, mom);
192 if (part->PolzIsSet()) {
194 part->GetPolarization(polz);
195 tpart.SetPolarization(polz);
202 truthcol->push_back(truth);
204 e.
put(std::move(truthcol));
221 std::string pdg_string =
std::to_string(static_cast<long long>(pdg_code));
222 if (pdg_string.size() != 10) {
223 std::cout <<
"Expecting PDG code to be a 10-digit integer; instead, it's the following: " 224 << pdg_string << std::endl;
229 int n_nucleons = std::stoi(pdg_string.substr(6, 3)) - 1;
230 int n_protons = std::stoi(pdg_string.substr(3, 3));
233 double proton_frac = ((double)n_protons) / ((double)n_nucleons);
234 double neutron_frac = 1 - proton_frac;
237 const int n_modes = 16;
238 double br[n_modes] = {0.010,
255 for (
int i = 0; i < n_modes; i++) {
257 br[i] *= proton_frac;
259 br[i] *= neutron_frac;
266 double threshold = 0;
267 for (
int i = 0; i < n_modes; i++) {
277 std::cout <<
"Random selection of final state failed!" << std::endl;
details::range_type< T > Iterate() const
Initializes the specified ID with the ID of the first cryostat.
base_engine_t & createEngine(seed_t seed)
NeutronOsc(fhicl::ParameterSet const &p)
void beginRun(art::Run &run) override
void SetOrigin(simb::Origin_t origin)
EDProducer(fhicl::ParameterSet const &pset)
Geometry information for a single TPC.
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Functions for transforming GENIE objects into ART objects (and back)
int SelectAnnihilationMode(int pdg_code)
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
#define DEFINE_ART_MODULE(klass)
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
void produce(art::Event &e) override
const genie::EventRecordVisitorI * mcgen
void Add(simb::MCParticle const &part)
void SetEventGeneratorListAndTune(const std::string &evtlistname="", const std::string &tunename="${GENIE_XSEC_TUNE}")
genie::NNBarOscMode_t gOptDecayMode
cout<< "-> Edep in the target
std::string const & DetectorName() const
Returns a string with the name of the detector, as configured.
Event generator information.
Namespace collecting geometry-related classes utilities.
Event Generation using GENIE, cosmics or single particles.
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Event finding and building.
The data type to uniquely identify a cryostat.
NeutronOsc & operator=(NeutronOsc const &)=delete