All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.
9 #include "art/Framework/Core/EDAnalyzer.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "art/Framework/Principal/Handle.h"
12 #include "art/Framework/Core/ModuleMacros.h"
13 #include "art/Framework/Principal/Run.h"
14 #include "art_root_io/TFileDirectory.h"
15 #include "art_root_io/TFileService.h"
16 #include "art/Framework/Services/Registry/ServiceHandle.h"
17 #include "art/Framework/Principal/Provenance.h"
18 #include "nusimdata/SimulationBase/MCParticle.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 
34 class larg4::CheckMCParticle : public art::EDAnalyzer {
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 
42  std::string const _myName;
43  TH1F* _hnParts{nullptr};
44 };
45 
46 larg4::CheckMCParticle::CheckMCParticle(fhicl::ParameterSet const& p) :
47  art::EDAnalyzer(p),
48  _myName(p.get<std::string>("name", "CheckMCParticle"))
49 {}
50 
52 {
53  art::ServiceHandle<art::TFileService const> tfs;
54  _hnParts = tfs->make<TH1F>("hnParts", "Number of generated Particles", 100, 0., 2000.);
55 } // end beginJob
56 
57 void larg4::CheckMCParticle::analyze(const art::Event& event)
58 {
59 #if defined _verbose_
60 
61  auto allDropped = event.getMany<std::map<int,std::set<int>>>();
62 
63  for (auto const& maps : allDropped ) {
64  for (auto const& element : *maps ) {
65  std::cout << "Parent of dropped Tracks: "<<element.first<< std::endl;
66  std::set<int> droppedset= element.second;
67  std::cout<< " droppedid size: "<< droppedset.size()<<std::endl;
68  for(auto const& droppedid : droppedset )
69  {
70  std::cout << droppedid << " ";
71  }
72  std::cout <<std::endl;
73  }
74  }
75 
76 #endif
77  auto allGens = event.getMany<std::vector<simb::MCParticle>>();
78  for (auto const& gens : allGens) {
79  _hnParts->Fill(gens->size());
80 #if defined _verbose_
81  for (auto const& genpart : *gens) {
82  if (genpart.Mother()==0) {
83  cout << "Primary momentum: " << genpart.P();
84  cout << " position: " << genpart.Vx()<< " "<< genpart.Vy()<<" "<< genpart.Vz() << 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  {
101  cout << genpart.Daughter(i)<<",";
102  }
103  cout<<endl;
104  }
105 #endif
106  }
107 } // end analyze
108 
109 DEFINE_ART_MODULE(larg4::CheckMCParticle)
process_name opflashCryo1 flashfilter analyze
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
standard_singlep gaussian distribution ie ie ie gaussian gaussian gaussian larg4Main CheckMCParticle
Definition: multigen.fcl:18
CheckMCParticle(fhicl::ParameterSet const &p)
pdgs p
Definition: selectors.fcl:22
void analyze(const art::Event &event) override
art::ServiceHandle< art::TFileService > tfs
BEGIN_PROLOG could also be cout