46 #include "Algorithm/AlgFactory.h" 47 #include "EVGCore/EventRecordVisitorI.h" 48 #include "EVGCore/EventRecord.h" 49 #include "NeutronOsc/NeutronOscMode.h" 50 #include "PDG/PDGLibrary.h" 51 #include "GHEP/GHepParticle.h" 52 #include "Utils/AppInit.h" 67 #include "CLHEP/Random/RandFlat.h" 98 const genie::EventRecordVisitorI *
mcgen;
105 genie::PDGLibrary::Instance();
107 string sname =
"genie::EventGenerator";
108 string sconfig =
"NeutronOsc";
109 genie::AlgFactory * algf = genie::AlgFactory::Instance();
111 dynamic_cast<const genie::EventRecordVisitorI *
> (algf->GetAlgorithm(sname,sconfig));
113 throw cet::exception(
"NeutronOsc") <<
"Couldn't instantiate the neutron-antineutron oscillation generator";
115 int fDecayMode = p.
get<
int>(
"DecayMode");
118 produces< std::vector<simb::MCTruth> >();
119 produces< sumdata::RunData, art::InRun >();
126 unsigned int seed = art::ServiceHandle<rndm::NuRandomService>()->getSeed();
127 genie::utils::app_init::RandGen(seed);
133 genie::EventRecord *
event =
new genie::EventRecord;
136 genie::Interaction * interaction = genie::Interaction::NOsc(target,decay);
137 event->AttachSummary(interaction);
148 <<
"Generated event: " << *
event;
150 std::unique_ptr< std::vector<simb::MCTruth> > truthcol(
new std::vector<simb::MCTruth>);
155 CLHEP::HepRandomEngine &engine = rng->
getEngine();
156 CLHEP::RandFlat flat(engine);
165 for (
size_t i = 0; i<geo->
NTPC(); ++i){
167 if (minx>tpc.
MinX()) minx = tpc.
MinX();
168 if (maxx<tpc.
MaxX()) maxx = tpc.
MaxX();
169 if (miny>tpc.
MinY()) miny = tpc.
MinY();
170 if (maxy<tpc.
MaxY()) maxy = tpc.
MaxY();
171 if (minz>tpc.
MinZ()) minz = tpc.
MinZ();
172 if (maxz<tpc.
MaxZ()) maxz = tpc.
MaxZ();
176 double X0 = flat.fire( minx, maxx );
177 double Y0 = flat.fire( miny, maxy );
178 double Z0 = flat.fire( minz, maxz );
180 TIter partitr(
event);
181 genie::GHepParticle *
part = 0;
186 std::string primary(
"primary");
188 while( (part = dynamic_cast<genie::GHepParticle *>(partitr.Next())) ){
197 TLorentzVector pos(X0, Y0, Z0, 0);
198 TLorentzVector mom(part->Px(), part->Py(), part->Pz(), part->E());
199 tpart.AddTrajectoryPoint(pos,mom);
200 if(part->PolzIsSet()) {
202 part->GetPolarization(polz);
203 tpart.SetPolarization(polz);
210 truthcol->push_back(truth);
212 e.
put(std::move(truthcol));
226 run.
put(std::move(runcol));
243 std::string pdg_string =
std::to_string(static_cast<long long>(pdg_code));
244 if (pdg_string.size() != 10) {
245 std::cout <<
"Expecting PDG code to be a 10-digit integer; instead, it's the following: " << pdg_string << std::endl;
250 int n_nucleons = std::stoi(pdg_string.substr(6,3)) - 1;
251 int n_protons = std::stoi(pdg_string.substr(3,3));
254 double proton_frac = ((double)n_protons) / ((double)n_nucleons);
255 double neutron_frac = 1 - proton_frac;
258 const int n_modes = 16;
259 double br [n_modes] = { 0.010, 0.080, 0.100, 0.220,
260 0.360, 0.160, 0.070, 0.020,
261 0.015, 0.065, 0.110, 0.280,
262 0.070, 0.240, 0.100, 0.100 };
264 for (
int i = 0; i < n_modes; i++) {
266 br[i] *= proton_frac;
268 br[i] *= neutron_frac;
273 CLHEP::HepRandomEngine &engine = rng->
getEngine();
274 CLHEP::RandFlat flat(engine);
275 double p = flat.fire();
278 double threshold = 0;
279 for (
int i = 0; i < n_modes; i++) {
289 std::cout <<
"Random selection of final state failed!" << std::endl;
NeutronOsc(fhicl::ParameterSet const &p)
void beginRun(art::Run &run) override
void SetOrigin(simb::Origin_t origin)
cout<< "-> Edep in the target
double MinX() const
Returns the world x coordinate of the start of the box.
Geometry information for a single TPC.
double MaxX() const
Returns the world x coordinate of the end of the box.
art::ProductID put(std::unique_ptr< PROD > &&)
void Add(simb::MCParticle &part)
int SelectAnnihilationMode(int pdg_code)
ProductID put(std::unique_ptr< PROD > &&product)
base_engine_t & getEngine() const
base_engine_t & createEngine(seed_t seed)
#define DEFINE_ART_MODULE(klass)
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
T get(std::string const &key) const
double MinZ() const
Returns the world z coordinate of the start of the box.
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
void produce(art::Event &e) override
double MaxY() const
Returns the world y coordinate of the end of the box.
const genie::EventRecordVisitorI * mcgen
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
genie::NeutronOscMode_t gOptDecayMode
double MaxZ() const
Returns the world z coordinate of the end of the box.
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
Event generator information.
Namespace collecting geometry-related classes utilities.
double MinY() const
Returns the world y coordinate of the start of the box.
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.
NeutronOsc & operator=(NeutronOsc const &)=delete