NucleonDecay_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // 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
10 // http://www-pdg.lbl.gov/2016/listings/rpp2016-list-p.pdf (tau1 through tau60)
11 //
12 ////////////////////////////////////////////////////////////////////////
13 
18 #include "fhiclcpp/ParameterSet.h"
20 
21 // GENIE includes
30 
31 // larsoft includes
34 
35 #include "nugen/EventGeneratorBase/GENIE/GENIE2ART.h"
36 
39 #include "nurandom/RandomUtils/NuRandomService.h"
40 
41 // c++ includes
42 #include <memory>
43 #include <string>
44 
45 #include "CLHEP/Random/RandFlat.h"
46 
47 namespace evgen {
48  class NucleonDecay;
49 }
50 
52 public:
53  explicit NucleonDecay(fhicl::ParameterSet const & p);
54  // The destructor generated by the compiler is fine for classes
55  // without bare pointers or other resource use.
56 
57  // Plugins should not be copied or assigned.
58  NucleonDecay(NucleonDecay const &) = delete;
59  NucleonDecay(NucleonDecay &&) = delete;
60  NucleonDecay & operator = (NucleonDecay const &) = delete;
61  NucleonDecay & operator = (NucleonDecay &&) = delete;
62 
63  // Required functions.
64  void produce(art::Event & e) override;
65 
66  // Selected optional functions.
67  void beginRun(art::Run& run) override;
68 
69 private:
70 
71  // Declare member data here.
74  int dpdg = 0;
75  CLHEP::RandFlat flatDist;
76 };
77 
78 
80  : art::EDProducer{p}
81  // create a default random engine; obtain the random seed from NuRandomService,
82  // unless overridden in configuration with key "Seed"
83  , flatDist{art::ServiceHandle<rndm::NuRandomService>{}->createEngine(*this, p, "Seed")}
84 {
85  genie::PDGLibrary::Instance(); //Ensure Messenger is started first in GENIE.
86 
87  string sname = "genie::EventGenerator";
88  string sconfig = "NucleonDecay";
89  // GENIE v3 needs a tune (even if irrelevant)
90  evgb::SetEventGeneratorListAndTune("Default","Default");
91 
93  mcgen =
94  dynamic_cast<const genie::EventRecordVisitorI *> (algf->GetAlgorithm(sname,sconfig));
95  if(!mcgen) {
96  throw cet::exception("NucleonDecay") << "Couldn't instantiate the nucleon decay generator";
97  }
98  int fDecayMode = p.get<int>("DecayMode");
100 
101  if (p.get<int>("DecayedNucleon") > 0 ){
102  dpdg = p.get<int>("DecayedNucleon");
103  }
104  else{
106  }
107 
108  produces< std::vector<simb::MCTruth> >();
109  produces< sumdata::RunData, art::InRun >();
110 
111  unsigned int seed = art::ServiceHandle<rndm::NuRandomService>()->getSeed();
113 }
114 
116 {
117  // Implementation of required member function here.
119  int target = 1000180400; //Only use argon target
120  int decay = (int)gOptDecayMode;
122  event->AttachSummary(interaction);
123 
124  // Simulate decay
126 
127 // genie::Interaction *inter = event->Summary();
128 // const genie::InitialState &initState = inter->InitState();
129 // std::cout<<"initState = "<<initState.AsString()<<std::endl;
130 // const genie::ProcessInfo &procInfo = inter->ProcInfo();
131 // std::cout<<"procInfo = "<<procInfo.AsString()<<std::endl;
132  MF_LOG_DEBUG("NucleonDecay")
133  << "Generated event: " << *event;
134 
135  std::unique_ptr< std::vector<simb::MCTruth> > truthcol(new std::vector<simb::MCTruth>);
136  simb::MCTruth truth;
137 
139 
140  // Find boundary of active volume
141  double minx = 1e9;
142  double maxx = -1e9;
143  double miny = 1e9;
144  double maxy = -1e9;
145  double minz = 1e9;
146  double maxz = -1e9;
147  for (size_t i = 0; i<geo->NTPC(); ++i){
148  const geo::TPCGeo &tpc = geo->TPC(i);
149  if (minx>tpc.MinX()) minx = tpc.MinX();
150  if (maxx<tpc.MaxX()) maxx = tpc.MaxX();
151  if (miny>tpc.MinY()) miny = tpc.MinY();
152  if (maxy<tpc.MaxY()) maxy = tpc.MaxY();
153  if (minz>tpc.MinZ()) minz = tpc.MinZ();
154  if (maxz<tpc.MaxZ()) maxz = tpc.MaxZ();
155  }
156 
157  // Assign vertice position
158  double X0 = flatDist.fire( minx, maxx );
159  double Y0 = flatDist.fire( miny, maxy );
160  double Z0 = flatDist.fire( minz, maxz );
161 
162  TIter partitr(event);
163  genie::GHepParticle *part = 0;
164  // GHepParticles return units of GeV/c for p. the V_i are all in fermis
165  // and are relative to the center of the struck nucleus.
166  // add the vertex X/Y/Z to the V_i for status codes 0 and 1
167  int trackid = 0;
168  std::string primary("primary");
169 
170  while( (part = dynamic_cast<genie::GHepParticle *>(partitr.Next())) ){
171 
172  simb::MCParticle tpart(trackid,
173  part->Pdg(),
174  primary,
175  part->FirstMother(),
176  part->Mass(),
177  part->Status());
178 
179  TLorentzVector pos(X0, Y0, Z0, 0);
180  TLorentzVector mom(part->Px(), part->Py(), part->Pz(), part->E());
181  tpart.AddTrajectoryPoint(pos,mom);
182  if(part->PolzIsSet()) {
183  TVector3 polz;
184  part->GetPolarization(polz);
185  tpart.SetPolarization(polz);
186  }
187  tpart.SetRescatter(part->RescatterCode());
188  truth.Add(tpart);
189 
190  ++trackid;
191  }// end loop to convert GHepParticles to MCParticles
192  truth.SetOrigin(simb::kUnknown);
193  truthcol->push_back(truth);
194  //FillHistograms(truth);
195  e.put(std::move(truthcol));
196 
197  delete event;
198 }
199 
201 {
203  run.put(std::make_unique<sumdata::RunData>(geo->DetectorName()));
204 }
205 
void RandGen(long int seed)
Definition: AppInit.cxx:30
genie::NucleonDecayMode_t gOptDecayMode
int RescatterCode(void) const
Definition: GHepParticle.h:65
NucleonDecay(fhicl::ParameterSet const &p)
virtual void ProcessEventRecord(GHepRecord *event_rec) const =0
double E(void) const
Get energy.
Definition: GHepParticle.h:91
CLHEP::RandFlat flatDist
void SetOrigin(simb::Origin_t origin)
Definition: MCTruth.h:82
Defines the EventRecordVisitorI interface. Concrete implementations of this interface use the &#39;Visito...
std::string string
Definition: nybbler.cc:12
const genie::EventRecordVisitorI * mcgen
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:88
Geometry information for a single TPC.
Definition: TPCGeo.h:38
static Interaction * NDecay(int tgt, int decay_mode=-1, int decayed_nucleon=0)
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:91
double Mass(void) const
Mass that corresponds to the PDG code.
Particle class.
void beginRun(art::Run &run) override
double Pz(void) const
Get Pz.
Definition: GHepParticle.h:90
GHepStatus_t Status(void) const
Definition: GHepParticle.h:64
art framework interface to geometry description
Definition: Run.h:17
double Px(void) const
Get Px.
Definition: GHepParticle.h:88
int Pdg(void) const
Definition: GHepParticle.h:63
int FirstMother(void) const
Definition: GHepParticle.h:66
Summary information for an interaction.
Definition: Interaction.h:56
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
def move(depos, offset)
Definition: depos.py:107
const Algorithm * GetAlgorithm(const AlgId &algid)
Definition: AlgFactory.cxx:75
double MinZ() const
Returns the world z coordinate of the start of the box.
p
Definition: test.py:223
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
void produce(art::Event &e) override
bool PolzIsSet(void) const
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.
void GetPolarization(TVector3 &polz)
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
NucleonDecay & operator=(NucleonDecay const &)=delete
void Add(simb::MCParticle const &part)
Definition: MCTruth.h:80
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:57
static AlgFactory * Instance()
Definition: AlgFactory.cxx:64
double MaxZ() const
Returns the world z coordinate of the end of the box.
enum genie::ENucleonDecayMode NucleonDecayMode_t
#define MF_LOG_DEBUG(id)
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
The GENIE Algorithm Factory.
Definition: AlgFactory.h:39
Event generator information.
Definition: MCTruth.h:32
LArSoft geometry interface.
Definition: ChannelGeo.h:16
double MinY() const
Returns the world y coordinate of the start of the box.
Event Generation using GENIE, cosmics or single particles.
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
int DecayedNucleonPdgCode(NucleonDecayMode_t ndm)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Event finding and building.
double Py(void) const
Get Py.
Definition: GHepParticle.h:89