24 #include "TDatabasePDG.h" 27 #include "CLHEP/Random/RandFlat.h" 54 #include "TStopwatch.h" 59 namespace simb {
class MCTruth; }
77 std::string ParticleStatus(
int StatusCode);
78 std::string ReactionChannel(
int ccnc,
int mode);
127 this->reconfigure(pset);
130 produces< std::vector<simb::MCTruth> >();
131 produces< sumdata::RunData, art::InRun >();
133 fEventFile =
new std::ifstream(fNdkFile.c_str());
134 if(!fEventFile->good())
139 ->createEngine(*
this, pset,
"Seed");
152 fNdkFile =(p.
get< std::string >(
"NdkFile"));
162 fGenerated[0] = tfs->
make<TH1F>(
"fGenerated_necc",
"", 100, 0.0, 20.0);
163 fGenerated[1] = tfs->
make<TH1F>(
"fGenerated_nebcc",
"", 100, 0.0, 20.0);
164 fGenerated[2] = tfs->
make<TH1F>(
"fGenerated_nmcc",
"", 100, 0.0, 20.0);
165 fGenerated[3] = tfs->
make<TH1F>(
"fGenerated_nmbcc",
"", 100, 0.0, 20.0);
166 fGenerated[4] = tfs->
make<TH1F>(
"fGenerated_nnc",
"", 100, 0.0, 20.0);
167 fGenerated[5] = tfs->
make<TH1F>(
"fGenerated_nbnc",
"", 100, 0.0, 20.0);
169 fDCosX = tfs->
make<TH1F>(
"fDCosX",
";dx/ds", 200, -1., 1.);
170 fDCosY = tfs->
make<TH1F>(
"fDCosY",
";dy/ds", 200, -1., 1.);
171 fDCosZ = tfs->
make<TH1F>(
"fDCosZ",
";dz/ds", 200, -1., 1.);
173 fMuMomentum = tfs->
make<TH1F>(
"fMuMomentum",
";p_{#mu} (GeV/c)", 500, 0., 50.);
174 fMuDCosX = tfs->
make<TH1F>(
"fMuDCosX",
";dx/ds;", 200, -1., 1.);
175 fMuDCosY = tfs->
make<TH1F>(
"fMuDCosY",
";dy/ds;", 200, -1., 1.);
176 fMuDCosZ = tfs->
make<TH1F>(
"fMuDCosZ",
";dz/ds;", 200, -1., 1.);
178 fEMomentum = tfs->
make<TH1F>(
"fEMomentum",
";p_{e} (GeV/c)", 500, 0., 50.);
179 fEDCosX = tfs->
make<TH1F>(
"fEDCosX",
";dx/ds;", 200, -1., 1.);
180 fEDCosY = tfs->
make<TH1F>(
"fEDCosY",
";dy/ds;", 200, -1., 1.);
181 fEDCosZ = tfs->
make<TH1F>(
"fEDCosZ",
";dz/ds;", 200, -1., 1.);
183 fCCMode = tfs->
make<TH1F>(
"fCCMode",
";CC Interaction Mode;", 5, 0., 5.);
184 fCCMode->GetXaxis()->SetBinLabel(1,
"QE");
185 fCCMode->GetXaxis()->SetBinLabel(2,
"Res");
186 fCCMode->GetXaxis()->SetBinLabel(3,
"DIS");
187 fCCMode->GetXaxis()->SetBinLabel(4,
"Coh");
188 fCCMode->GetXaxis()->SetBinLabel(5,
"kInverseMuDecay");
189 fCCMode->GetXaxis()->CenterLabels();
191 fNCMode = tfs->
make<TH1F>(
"fNCMode",
";NC Interaction Mode;", 5, 0., 5.);
192 fNCMode->GetXaxis()->SetBinLabel(1,
"QE");
193 fNCMode->GetXaxis()->SetBinLabel(2,
"Res");
194 fNCMode->GetXaxis()->SetBinLabel(3,
"DIS");
195 fNCMode->GetXaxis()->SetBinLabel(4,
"Coh");
196 fNCMode->GetXaxis()->SetBinLabel(5,
"kNuElectronElastic");
197 fNCMode->GetXaxis()->CenterLabels();
200 fECons = tfs->
make<TH1F>(
"fECons",
";#Delta E(#nu,lepton);", 500, -5., 5.);
206 int xdiv = TMath::Nint(2*x/5.);
207 int ydiv = TMath::Nint(2*y/5.);
208 int zdiv = TMath::Nint(2*z/5.);
210 fVertexX = tfs->
make<TH1F>(
"fVertexX",
";x (cm)", xdiv, -
x,
x);
211 fVertexY = tfs->
make<TH1F>(
"fVertexY",
";y (cm)", ydiv, -
y,
y);
212 fVertexZ = tfs->
make<TH1F>(
"fVertexZ",
";z (cm)", zdiv, -0.2*
z,
z);
214 fVertexXY = tfs->
make<TH2F>(
"fVertexXY",
";x (cm);y (cm)", xdiv, -
x,
x, ydiv, -
y,
y);
215 fVertexXZ = tfs->
make<TH2F>(
"fVertexXZ",
";z (cm);x (cm)", zdiv, -0.2*
z,
z, xdiv, -
x,
x);
216 fVertexYZ = tfs->
make<TH2F>(
"fVertexYZ",
";z (cm);y (cm)", zdiv, -0.2*
z,
z, ydiv, -
y,
y);
228 run.
put(std::move(runcol));
234 void NDKGen::endJob()
242 std::cout << std::endl;
243 std::cout<<
"------------------------------------------------------------------------------"<<std::endl;
247 std::cout <<
"event : " << evt.
id().
event() << std::endl;
265 std::string name, k, dollar;
272 int Idx, Ist, PDG, Mother1, Mother2, Daughter1 ,Daughter2;
273 double Px, Py, Pz,
E, m ;
274 std::string p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14;
278 std::string primary(
"primary");
279 int FirstMother = -1;
291 TLorentzVector Neutrino;
292 TLorentzVector Lepton;
293 TLorentzVector Target;
295 TLorentzVector Hadron4mom;
308 std::unique_ptr< std::vector<simb::MCTruth> > truthcol(
new std::vector<simb::MCTruth>);
313 CLHEP::HepRandomEngine &engine = rng->
getEngine();
314 CLHEP::RandFlat flat(engine);
325 for (
size_t i = 0; i<geo->
NTPC(); ++i)
327 double local[3] = {0.,0.,0.};
328 double world[3] = {0.,0.,0.};
346 double X0 = 0.0 + flat.fire( minx+fvCut , maxx-fvCut );
347 double Y0 = 0.0 + flat.fire( miny+fvCut , maxy-fvCut );
348 double Z0 = 0.0 + flat.fire( minz+fvCut , maxz-fvCut );
350 std::cout <<
"NDKGen_module: X, Y, Z of vtx: " << X0 <<
", "<< Y0 <<
", "<< Z0 << std::endl;
354 if(!fEventFile->good())
355 std::cout <<
"NdkFile: Problem reading Ndk file" << std::endl;
357 while(getline(*fEventFile,k)){
359 if (k.find(
"** Event:")!= std::string::npos) {
360 std::istringstream
in;
364 in>> dummy>> dummy>> dummy >> dummy>> dummy>> dummy>> dummy >> dummy>> dummy>> dummy >> GenieEvt;
365 std::cout<<
"Genie Evt "<< GenieEvt <<
" art evt "<<evt.
id().
event()<<
"\n";
368 if (GenieEvt+1 != static_cast<int>(evt.
id().
event()))
372 if (!k.compare(0,25,
"GENIE Interaction Summary"))
374 if (k.compare(0,1,
"|") || k.compare(1,2,
" "))
continue;
375 if (k.find(
"Fin-Init") != std::string::npos)
continue;
376 if (k.find(
"Ar") != std::string::npos)
continue;
377 if (k.find(
"Cl") != std::string::npos)
continue;
378 if (k.find(
"HadrBlob") != std::string::npos)
continue;
379 if (k.find(
"NucBindE") != std::string::npos)
continue;
380 if (k.find(
"FLAGS") != std::string::npos)
break;
381 if (k.find(
"Vertex") != std::string::npos)
break;
384 if (!k.compare(26,1,
"1"))
387 std::istringstream
in;
391 in>>p1>> Idx >>p2>> Name >>p3>> Ist >>p4>> PDG >>p5>>Mother1 >> p6 >> Mother2 >>p7>> Daughter1 >>p8>> Daughter2 >>p9>>Px>>p10>>Py>>p11>>Pz>>p12>>E>>p13>> m>>p14;
393 if (Ist!=1)
continue;
395 std::cout <<
"PDG = " << PDG << std::endl;
397 const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
398 const TParticlePDG* definition = databasePDG->GetParticle(PDG);
399 Mass = definition->Mass();
400 if (E-Mass < 0.001)
continue;
413 P = std::sqrt(pow(E,2.) - pow(Mass,2.));
414 std::cout <<
"Momentum = " << P << std::endl;
416 TLorentzVector pos(X0, Y0, Z0, 0);
420 TLorentzVector mom(Px,Py,Pz, E);
436 std::cout <<
"NDKGen.cxx: Putting " << truth.
NParticles() <<
" tracks on stack." << std::endl;
437 truthcol->push_back(truth);
439 evt.
put(std::move(truthcol));
445 std::string NDKGen::ParticleStatus(
int StatusCode)
447 int code = StatusCode;
453 ParticleStatusName =
"kIStInitialState";
456 ParticleStatusName =
"kIStFinalState";
459 ParticleStatusName =
"kIStNucleonTarget";
462 ParticleStatusName =
"Status Unknown";
469 std::string NDKGen::ReactionChannel(
int ccnc,
int mode)
471 std::string ReactionChannelName=
" ";
474 ReactionChannelName =
"kCC";
476 ReactionChannelName =
"kNC";
477 else std::cout<<
"Current mode unknown!! "<<std::endl;
480 ReactionChannelName +=
"_kQE";
482 ReactionChannelName +=
"_kRes";
484 ReactionChannelName +=
"_kDIS";
486 ReactionChannelName +=
"_kCoh";
488 ReactionChannelName +=
"_kNuElectronElastic";
490 ReactionChannelName +=
"_kInverseMuDecay";
491 else std::cout<<
"interaction mode unknown!! "<<std::endl;
493 return ReactionChannelName;
524 fVertexX->Fill(nu.
Vx());
525 fVertexY->Fill(nu.
Vy());
526 fVertexZ->Fill(nu.
Vz());
528 fVertexXY->Fill(nu.
Vx(), nu.
Vy());
529 fVertexXZ->Fill(nu.
Vz(), nu.
Vx());
530 fVertexYZ->Fill(nu.
Vz(), nu.
Vy());
533 if(std::abs(mom) > 0.){
534 fDCosX->Fill(nu.
Px()/mom);
535 fDCosY->Fill(nu.
Py()/mom);
536 fDCosZ->Fill(nu.
Pz()/mom);
580 std::cout <<
"-----------> Particles in the Stack = " << mc.
NParticles() << std::endl;
582 << std::setw(20) <<
"PARTICLE" 584 << std::setw(32) <<
"STATUS" 585 << std::setw(18) <<
"E (GeV)" 586 << std::setw(18) <<
"m (GeV/c2)" 587 << std::setw(18) <<
"Ek (GeV)" 588 << std::endl << std::endl;
590 const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
596 if (
part.PdgCode() == 18040)
598 else if (
part.PdgCode() != -99999 )
600 name = databasePDG->GetParticle(
part.PdgCode())->GetName();
603 int code =
part.StatusCode();
604 std::string status = ParticleStatus(code);
605 double mass =
part.Mass();
607 double Ek = (energy-mass);
609 std::cout << std::setiosflags(
std::ios::left) << std::setw(20) << name
611 << std::setw(18)<< energy
612 << std::setw(18)<< mass
613 << std::setw(18)<< Ek <<std::endl;
622 if(abs(
part.PdgCode()) == 11){
623 fEMomentum->Fill(
part.P());
627 fECons->Fill(nu.
E() -
part.E());
630 else if(abs(
part.PdgCode()) == 13){
631 fMuMomentum->Fill(
part.P());
635 fECons->Fill(nu.
E() -
part.E());
double E(const int i=0) const
TH1F * fMuMomentum
momentum of outgoing muons
TH2F * fVertexXY
vertex location in xy
const simb::MCNeutrino & GetNeutrino() const
double Py(const int i=0) const
TH1F * fMuDCosY
direction cosine of outgoing mu in y
TH1F * fMuDCosZ
direction cosine of outgoing mu in z
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
TH1F * fECons
histogram to determine if energy is conserved in the event
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
void SetOrigin(simb::Origin_t origin)
TH1F * fEDCosZ
direction cosine of outgoing e in z
const simb::MCParticle & Nu() const
TH1F * fEMomentum
momentum of outgoing electrons
TH2F * fVertexXZ
vertex location in xz
Geometry information for a single TPC.
double Px(const int i=0) const
TH1F * fVertexY
vertex location of generated events in y
art::ProductID put(std::unique_ptr< PROD > &&)
void Add(simb::MCParticle &part)
TH1F * fCCMode
CC interaction mode.
TH1F * fEDCosY
direction cosine of outgoing e in y
ProductID put(std::unique_ptr< PROD > &&product)
base_engine_t & getEngine() const
A module to check the results from the Monte Carlo generator.
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
#define DEFINE_ART_MODULE(klass)
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
double P(const int i=0) const
T get(std::string const &key) const
TH1F * fMuDCosX
direction cosine of outgoing mu in x
std::ifstream * fEventFile
TH2F * fVertexYZ
vertex location in yz
TH1F * fVertexZ
vertex location of generated events in z
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
TH1F * fDCosZ
direction cosine in z
std::string fNDKModuleLabel
keep track of how long it takes to run the job
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
const simb::MCParticle & GetParticle(int i) const
TH1F * fEDCosX
direction cosine of outgoing e in x
double Vx(const int i=0) const
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
T * make(ARGS...args) const
double Pz(const int i=0) const
double Vz(const int i=0) const
EventNumber_t event() const
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
Event generator information.
TH1F * fNCMode
CC interaction mode.
TH1F * fDCosY
direction cosine in y
Event generator information.
Namespace collecting geometry-related classes utilities.
Event Generation using GENIE, cosmics or single particles.
std::string ParticleStatusName(int code)
Describes the status of a particle (simb::MCParticle::StatusCode()).
TH1F * fVertexX
vertex location of generated events in x
void LocalToWorld(const double *tpc, double *world) const
Transform point from local TPC frame to world frame.
TH1F * fDCosX
direction cosine in x
double Vy(const int i=0) const
art framework interface to geometry description