LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CheckGenParticle_module.cc
Go to the documentation of this file.
1 //
2 // __ __ __ __ __
3 // ____ ______/ /_____ _/ // / / /_/ /__
4 // / __ `/ ___/ __/ __ `/ // /_/ __/ //_/
5 // / /_/ / / / /_/ /_/ /__ __/ /_/ ,<
6 // \__,_/_/ \__/\__, / /_/ \__/_/|_|
7 // /____/
8 //
9 // artg4tk: art based Geant 4 Toolkit
10 //
11 //=============================================================================
12 // CheckGenParticle_module.cc: Analysis module to analyze the GenParticles
13 // in the Event
14 // Author: Hans Wenzel (Fermilab)
15 //=============================================================================
16 
17 // C++ includes.
18 #include <iostream>
19 #include <string>
20 
21 // Framework includes.
28 #include "art_root_io/TFileService.h"
29 
30 // artg4tk includes:
33 
34 // Root includes.
35 #include "TDirectory.h"
36 #include "TH1F.h"
37 
38 using namespace std;
39 namespace artg4tk {
40  class CheckGenParticle;
41 }
42 
44 public:
45  explicit CheckGenParticle(fhicl::ParameterSet const& p);
46  void beginJob() override;
47  void beginRun(const art::Run& Run) override;
48  void endJob() override;
49  void analyze(const art::Event& event) override;
50 
51 private:
52  std::string _myName;
53  TH1F* _hnParts;
54  TDirectory const* _directory;
55  TFile* _file;
56 };
57 
59  : art::EDAnalyzer(p)
60  , _myName(p.get<std::string>("name", "CheckGenParticle"))
61  , _hnParts(0)
62  , _directory(0)
63  , _file(0)
64 {}
65 
66 void
68 {
69  std::cout << "******************************Run: " << thisRun.id() << ": looking at Run Header"
70  << std::endl;
71 }
72 
73 void
75 {
76 
78  _directory = gDirectory;
79  std::cout << "******************************We are in the directory named: "
80  << gDirectory->GetName() << std::endl;
81  _file = gDirectory->GetFile();
82  _hnParts = tfs->make<TH1F>("hnParts", "Number of generated Particles", 100, 0., 2000.);
83 } // end beginJob
84 
85 void
87 {
88  std::cout << "******************************event " << event.id().event()
89  << ": looking at GenParticles" << std::endl;
90  typedef std::vector<art::Handle<GenParticleCollection>> HandleVector;
91  // HandleVector allGens;
92  // event.getManyByType(allGens);
93  auto allGens = event.getMany<GenParticleCollection>();
94 
95  cout << "GenParticles*********************Size: " << allGens.size() << endl;
96  for (HandleVector::const_iterator i = allGens.begin(); i != allGens.end(); ++i) {
97  const GenParticleCollection& gens(**i);
98  cout << " ********************************CheckGenParticle: collection size: " << gens.size()
99  << endl;
100  _hnParts->Fill(gens.size());
101  for (GenParticleCollection::const_iterator j = gens.begin(); j != gens.end(); ++j) {
102  const GenParticle& genpart = *j;
103  cout << "Part id: " << genpart.pdgId() << endl;
104  CLHEP::HepLorentzVector const& mom = genpart.momentum();
105  cout << "Part Energy: " << mom.e() << endl;
106  cout << "invariant mass: " << mom.invariantMass() << endl;
107  cout << "momentum: " << mom.pz() << endl;
108  cout << genpart << endl;
109  }
110  }
111 
112 } // end analyze
113 
114 void
116 {
117  cout << " ********************************CheckGenParticle: I am done " << endl;
118 }
119 
RunID id() const
Definition: Run.cc:21
STL namespace.
intermediate_table::const_iterator const_iterator
void analyze(const art::Event &event) override
std::vector< GenParticle > GenParticleCollection
void beginRun(const art::Run &Run) override
Definition: Run.h:37
CheckGenParticle(fhicl::ParameterSet const &p)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void beginJob()
Definition: Breakpoints.cc:14
PDGCode::type pdgId() const
Definition: GenParticle.hh:35
CLHEP::HepLorentzVector const & momentum() const
Definition: GenParticle.hh:60
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
Definition: MVAAlg.h:12
Event finding and building.