CheckMCParticle_module.cc
Go to the documentation of this file.
1 // C++ includes.
2 #include <iostream>
3 #include <string>
4 #include <set>
5 #include <cmath>
6 #include <algorithm>
7 
8 // Framework includes.
14 #include "art_root_io/TFileDirectory.h"
15 #include "art_root_io/TFileService.h"
19 
20 // Root includes.
21 #include "TFile.h"
22 #include "TH1F.h"
23 #include "TH2F.h"
24 #include "TDirectory.h"
25 
26 // Other includes.
27 #include "CLHEP/Units/SystemOfUnits.h"
28 //#define _verbose_ 1
29 using namespace std;
30 namespace larg4 {
31  class CheckMCParticle;
32 }
33 
35 public:
36  explicit CheckMCParticle(fhicl::ParameterSet const& p);
37 
38 private:
39  void beginJob() override;
40  void analyze(const art::Event& event) override;
41 
43  TH1F* _hnParts{nullptr};
44 };
45 
47  art::EDAnalyzer(p),
48  _myName(p.get<std::string>("name", "CheckMCParticle"))
49 {}
50 
52 {
54  _hnParts = tfs->make<TH1F>("hnParts", "Number of generated Particles", 100, 0., 2000.);
55 } // end beginJob
56 
58 {
59  auto allGens = event.getMany<std::vector<simb::MCParticle>>();
60  for (auto const& gens : allGens) {
61  _hnParts->Fill(gens->size());
62 #if defined _verbose_
63  for (auto const& genpart : *gens) {
64  cout << "Part id: " << genpart.TrackId() << endl;
65  cout << "PDG id: " << genpart.PdgCode() << endl;
66  cout << "Status Code: " << genpart.StatusCode() << endl;
67  cout << "Mother: " << genpart.Mother() << endl;
68  if (genpart.Mother()==0) {
69  cout << "momentum: " << genpart.P() << endl;
70  cout << "position: " << genpart.Vx()<< " "<< genpart.Vy()<<" "<< genpart.Vz() << endl;
71  }
72  }
73 #endif
74  }
75 } // end analyze
76 
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:69
CheckMCParticle(fhicl::ParameterSet const &p)
std::string string
Definition: nybbler.cc:12
Geant4 interface.
STL namespace.
Particle class.
void analyze(const art::Event &event) override
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void beginJob()
Definition: Breakpoints.cc:14
p
Definition: test.py:223
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
QTextStream & endl(QTextStream &s)
Event finding and building.