LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
NucleonDecay_module.cc
Go to the documentation of this file.
1 // Class: NucleonDecay
3 // Module Type: producer
4 // GENIE nucleon decay generator
5 //
6 // Converted from gNucleonDecayEvGen.cxx by
7 // tjyang@fnal.gov
8 //
9 // 2016 PDG numbering scheme in pp.8-10 of http://www-pdg.lbl.gov/2016/listings/rpp2016-list-p.pdf (tau1 through tau60)
10 //
12 
20 #include "fhiclcpp/ParameterSet.h"
22 
23 // GENIE includes
24 #include "Algorithm/AlgFactory.h"
25 #include "EVGCore/EventRecordVisitorI.h"
26 #include "EVGCore/EventRecord.h"
27 #include "NucleonDecay/NucleonDecayMode.h"
28 #include "NucleonDecay/NucleonDecayUtils.h"
29 #include "PDG/PDGLibrary.h"
30 #include "GHEP/GHepParticle.h"
31 #include "Utils/AppInit.h"
32 
33 // larsoft includes
41 
42 // c++ includes
43 #include <memory>
44 #include <string>
45 
46 #include "CLHEP/Random/RandFlat.h"
47 
48 namespace evgen {
49  class NucleonDecay;
50 }
51 
53 public:
54  explicit NucleonDecay(fhicl::ParameterSet const & p);
55  // The destructor generated by the compiler is fine for classes
56  // without bare pointers or other resource use.
57 
58  // Plugins should not be copied or assigned.
59  NucleonDecay(NucleonDecay const &) = delete;
60  NucleonDecay(NucleonDecay &&) = delete;
61  NucleonDecay & operator = (NucleonDecay const &) = delete;
62  NucleonDecay & operator = (NucleonDecay &&) = delete;
63 
64  // Required functions.
65  void produce(art::Event & e) override;
66 
67  // Selected optional functions.
68  void beginJob() override;
69  void beginRun(art::Run& run) override;
70 
71 private:
72 
73  // Declare member data here.
74  const genie::EventRecordVisitorI * mcgen;
75  genie::NucleonDecayMode_t gOptDecayMode = genie::kNDNull; // nucleon decay mode
76  int dpdg = 0;
77 };
78 
79 
81 {
82  genie::PDGLibrary::Instance(); //Ensure Messenger is started first in GENIE.
83 
84  string sname = "genie::EventGenerator";
85  string sconfig = "NucleonDecay";
86  genie::AlgFactory * algf = genie::AlgFactory::Instance();
87  mcgen =
88  dynamic_cast<const genie::EventRecordVisitorI *> (algf->GetAlgorithm(sname,sconfig));
89  if(!mcgen) {
90  throw cet::exception("NucleonDecay") << "Couldn't instantiate the nucleon decay generator";
91  }
92  int fDecayMode = p.get<int>("DecayMode");
93  gOptDecayMode = (genie::NucleonDecayMode_t) fDecayMode;
94 
95  if (p.get<int>("DecayedNucleon") > 0 ){
96  dpdg = p.get<int>("DecayedNucleon");
97  }
98  else{
99  dpdg = genie::utils::nucleon_decay::DecayedNucleonPdgCode(gOptDecayMode);
100  }
101 
102  produces< std::vector<simb::MCTruth> >();
103  produces< sumdata::RunData, art::InRun >();
104 
105  // create a default random engine; obtain the random seed from NuRandomService,
106  // unless overridden in configuration with key "Seed"
108  ->createEngine(*this, p, "Seed");
109 
110  unsigned int seed = art::ServiceHandle<rndm::NuRandomService>()->getSeed();
111  genie::utils::app_init::RandGen(seed);
112 }
113 
115 {
116  // Implementation of required member function here.
117  genie::EventRecord * event = new genie::EventRecord;
118  int target = 1000180400; //Only use argon target
119  int decay = (int)gOptDecayMode;
120  genie::Interaction * interaction = genie::Interaction::NDecay(target,decay,dpdg);
121  event->AttachSummary(interaction);
122 
123  // Simulate decay
124  mcgen->ProcessEventRecord(event);
125 
126 // genie::Interaction *inter = event->Summary();
127 // const genie::InitialState &initState = inter->InitState();
128 // std::cout<<"initState = "<<initState.AsString()<<std::endl;
129 // const genie::ProcessInfo &procInfo = inter->ProcInfo();
130 // std::cout<<"procInfo = "<<procInfo.AsString()<<std::endl;
131  LOG_DEBUG("NucleonDecay")
132  << "Generated event: " << *event;
133 
134  std::unique_ptr< std::vector<simb::MCTruth> > truthcol(new std::vector<simb::MCTruth>);
135  simb::MCTruth truth;
136 
139  CLHEP::HepRandomEngine &engine = rng->getEngine();
140  CLHEP::RandFlat flat(engine);
141 
142  // Find boundary of active volume
143  double minx = 1e9;
144  double maxx = -1e9;
145  double miny = 1e9;
146  double maxy = -1e9;
147  double minz = 1e9;
148  double maxz = -1e9;
149  for (size_t i = 0; i<geo->NTPC(); ++i){
150  const geo::TPCGeo &tpc = geo->TPC(i);
151  if (minx>tpc.MinX()) minx = tpc.MinX();
152  if (maxx<tpc.MaxX()) maxx = tpc.MaxX();
153  if (miny>tpc.MinY()) miny = tpc.MinY();
154  if (maxy<tpc.MaxY()) maxy = tpc.MaxY();
155  if (minz>tpc.MinZ()) minz = tpc.MinZ();
156  if (maxz<tpc.MaxZ()) maxz = tpc.MaxZ();
157  }
158 
159  // Assign vertice position
160  double X0 = flat.fire( minx, maxx );
161  double Y0 = flat.fire( miny, maxy );
162  double Z0 = flat.fire( minz, maxz );
163 
164  TIter partitr(event);
165  genie::GHepParticle *part = 0;
166  // GHepParticles return units of GeV/c for p. the V_i are all in fermis
167  // and are relative to the center of the struck nucleus.
168  // add the vertex X/Y/Z to the V_i for status codes 0 and 1
169  int trackid = 0;
170  std::string primary("primary");
171 
172  while( (part = dynamic_cast<genie::GHepParticle *>(partitr.Next())) ){
173 
174  simb::MCParticle tpart(trackid,
175  part->Pdg(),
176  primary,
177  part->FirstMother(),
178  part->Mass(),
179  part->Status());
180 
181  TLorentzVector pos(X0, Y0, Z0, 0);
182  TLorentzVector mom(part->Px(), part->Py(), part->Pz(), part->E());
183  tpart.AddTrajectoryPoint(pos,mom);
184  if(part->PolzIsSet()) {
185  TVector3 polz;
186  part->GetPolarization(polz);
187  tpart.SetPolarization(polz);
188  }
189  tpart.SetRescatter(part->RescatterCode());
190  truth.Add(tpart);
191 
192  ++trackid;
193  }// end loop to convert GHepParticles to MCParticles
194  truth.SetOrigin(simb::kUnknown);
195  truthcol->push_back(truth);
196  //FillHistograms(truth);
197  e.put(std::move(truthcol));
198 
199  delete event;
200  return;
201 
202 }
203 
205 {
206 
207  // grab the geometry object to see what geometry we are using
209  std::unique_ptr<sumdata::RunData> runcol(new sumdata::RunData(geo->DetectorName()));
210 
211  run.put(std::move(runcol));
212 
213  return;
214 }
215 
216 
218 {
219  // Implementation of optional member function here.
220 }
221 
genie::NucleonDecayMode_t gOptDecayMode
NucleonDecay(fhicl::ParameterSet const &p)
void SetOrigin(simb::Origin_t origin)
Definition: MCTruth.h:78
cout<< "-> Edep in the target
Definition: analysis.C:54
const genie::EventRecordVisitorI * mcgen
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:90
Geometry information for a single TPC.
Definition: TPCGeo.h:37
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:93
art::ProductID put(std::unique_ptr< PROD > &&)
Definition: Run.h:148
Particle class.
void Add(simb::MCParticle &part)
Definition: MCTruth.h:77
void beginRun(art::Run &run) override
Definition: Run.h:30
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
base_engine_t & getEngine() const
base_engine_t & createEngine(seed_t seed)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
long seed
Definition: chem4.cc:68
T get(std::string const &key) const
Definition: ParameterSet.h:231
TString part[npart]
Definition: Style.C:32
double MinZ() const
Returns the world z coordinate of the start of the box.
void produce(art::Event &e) override
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
double MaxY() const
Returns the world y coordinate of the end of the box.
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
NucleonDecay & operator=(NucleonDecay const &)=delete
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
double MaxZ() const
Returns the world z coordinate of the end of the box.
#define LOG_DEBUG(id)
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
Event generator information.
Definition: MCTruth.h:30
Float_t e
Definition: plot.C:34
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
Definition: exception.h:33
Event finding and building.