LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CheckMCParticle_module.cc
Go to the documentation of this file.
1 // C++ includes.
2 #include <algorithm>
3 #include <cmath>
4 #include <iostream>
5 #include <set>
6 #include <string>
7 
8 // Framework includes.
16 #include "art_root_io/TFileDirectory.h"
17 #include "art_root_io/TFileService.h"
20 
21 // Root includes.
22 #include "TDirectory.h"
23 #include "TFile.h"
24 #include "TH1F.h"
25 #include "TH2F.h"
26 
27 // Other includes.
28 #include "CLHEP/Units/SystemOfUnits.h"
29 //#define _verbose_ 1
30 using namespace std;
31 namespace larg4 {
32  class CheckMCParticle;
33 }
34 
36 public:
37  explicit CheckMCParticle(fhicl::ParameterSet const& p);
38 
39 private:
40  void beginJob() override;
41  void analyze(const art::Event& event) override;
42 
43  std::string const _myName;
44  TH1F* _hnParts{nullptr};
45 };
46 
48  : art::EDAnalyzer(p), _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 #if defined _verbose_
60 
61  auto allDropped = event.getMany<sim::ParticleAncestryMap>();
62 
63  for (auto const& maps : allDropped) {
64  auto const& map = maps->GetMap();
65  for (auto const& [parent, daughters] : map) {
66  std::cout << "Parent of dropped Tracks: " << parent << std::endl;
67  std::cout << " droppedid size: " << daughters.size() << std::endl;
68  for (auto const& droppedid : daughters) {
69  std::cout << droppedid << " ";
70  }
71  std::cout << std::endl;
72  }
73  }
74 
75 #endif
76  auto allGens = event.getMany<std::vector<simb::MCParticle>>();
77  for (auto const& gens : allGens) {
78  _hnParts->Fill(gens->size());
79 #if defined _verbose_
80  for (auto const& genpart : *gens) {
81  if (genpart.Mother() == 0) {
82  cout << "Primary momentum: " << genpart.P();
83  cout << " position: " << genpart.Vx() << " " << genpart.Vy() << " " << genpart.Vz()
84  << endl;
85  }
86  cout << "Part id: " << genpart.TrackId();
87  cout << " PDG id: " << genpart.PdgCode();
88  cout << " Status Code: " << genpart.StatusCode();
89  cout << " Mother: " << genpart.Mother();
90  cout << " Creation Process: " << genpart.Process();
91  cout << " End Process: " << genpart.EndProcess();
92  /*
93  auto trajectory = genpart.Trajectory();
94  cout <<" trajectory size: " << trajectory.size();
95  */
96  cout << " Nr. of Daughters: " << genpart.NumberDaughters();
97  cout << " FirstDaughter:" << genpart.FirstDaughter() << endl;
98  // cout <<" LastDaughter: " << genpart.LastDaughter() <<endl;
99  for (int i = 0; i < genpart.NumberDaughters(); i++) {
100  cout << genpart.Daughter(i) << ",";
101  }
102  cout << endl;
103  }
104 #endif
105  }
106 } // end analyze
107 
CheckMCParticle(fhicl::ParameterSet const &p)
Geant4 interface.
STL namespace.
Particle class.
void analyze(const art::Event &event) override
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void beginJob()
Definition: Breakpoints.cc:14
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
Definition: MVAAlg.h:12
std::map< int, std::set< int > > const & GetMap() const
Event finding and building.