PDSPmatchmc_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: PDSPmatchmc
3 // Plugin Type: analyzer (art v3_01_02)
4 // File: PDSPmatchmc_module.cc
5 //
6 // Generated at Wed May 1 16:53:19 2019 by Bryan Ramson using cetskelgen
7 // from cetlib version v3_05_01.
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include <numeric>
11 #include <sstream>
12 #include <string.h>
13 #include <bitset>
14 #include <vector>
15 
17 
25 #include "fhiclcpp/ParameterSet.h"
27 //#include "art/Framework/Services/Optional/TFileService.h"
28 #include "art_root_io/TFileService.h"
29 
32 //#include "dune/Geometry/ProtoDUNESPCRTSorter.h"
33 
35 #include "artdaq-core/Data/ContainerFragment.hh"
36 
38 #include "TTree.h"
39 #include "TH2.h"
40 #include "TLorentzVector.h"
41 #include "TVector3.h"
42 
50 //#include "nusimdata/SimulationBase/MCParticle.h"
51 //#include "nusimdata/SimulationBase/MCTrajectory.h"
58 #include "canvas/Persistency/Common/FindManyP.h"
63 
64 namespace pdsp {
65  class PDSPmatchmc;
66 }
67 
68 
70 public:
71  explicit PDSPmatchmc(fhicl::ParameterSet const& p);
72  // The compiler-generated destructor is fine for non-base
73  // classes without bare pointers or other resource use.
74 
75  // Plugins should not be copied or assigned.
76  PDSPmatchmc(PDSPmatchmc const&) = delete;
77  PDSPmatchmc(PDSPmatchmc&&) = delete;
78  PDSPmatchmc& operator=(PDSPmatchmc const&) = delete;
79  PDSPmatchmc& operator=(PDSPmatchmc&&) = delete;
80 
81  // Required functions.
82  void analyze(art::Event const& e) override;
83 
84  // Selected optional functions.
85  void beginJob() override;
86 
87 private:
88  // Declare member data here.
89 
90  const art::InputTag fOpHitLabel;//MC light hits
91  //const art::InputTag fPFParListLabel;//Label for MC PF Particle containers
92  const art::InputTag fMCTruthLabel;//Label for MC Truth
93  const art::InputTag fGEANTLabel;//GEANT Label for truth particles
94 
95  TTree *fTree;
96 
98 
99  std::vector<int64_t> fPDS_time;
100  std::vector<double> fOpChan, fPE;
101 };
102 
104  :
105  EDAnalyzer(p),
106  fOpHitLabel(p.get<art::InputTag>("OpHitLabel_MC")),
107  fMCTruthLabel(p.get<art::InputTag>("MCTruthLabel_MC")),
108  fGEANTLabel(p.get<art::InputTag>("GEANTLabel_MC"))
109  //: EDAnalyzer{p},
110  // ,
111  // More initializers here.
112 {
113  // Call appropriate consumes<>() for any products to be retrieved by this module.
114  consumes<std::vector<recob::OpHit>>(fOpHitLabel);
115  consumes<std::vector<simb::MCTruth>>(fMCTruthLabel);
116  consumes<std::vector<simb::MCParticle>>(fGEANTLabel);
117 }
118 
120 {
122 
123  bool op = false;
124  // Implementation of required member function here.
125  fTrueID.clear();
126  fTrue_time.clear();
127  fTrueStartx.clear();
128  fTrueStarty.clear();
129  fTrueStartz.clear();
130  fTruePx.clear();
131  fTruePy.clear();
132  fTruePz.clear();
133 
134  fPDS_time.clear();
135  fOpChan.clear();
136  fPE.clear();
137 
138  const auto MClistHandle = e.getValidHandle<std::vector<simb::MCTruth>>(fMCTruthLabel);
139  art::Ptr<simb::MCTruth> mctruth(MClistHandle,0);
140  if(mctruth->NParticles() == 0){
141  mf::LogError("PDSPmatchmc") << "No MCTruth Particles! Skipping.";
142  return;
143  }
144 
145  const auto OpHitHandle = e.getValidHandle<std::vector<recob::OpHit>>(fOpHitLabel);
146 
147  const simb::MCParticle& part(mctruth->GetParticle(0));
148  fTrueID.push_back(part.PdgCode());
149  fTrue_time.push_back(part.T());
150  fTrueStartx.push_back(part.Vx());
151  fTrueStarty.push_back(part.Vy());
152  fTrueStartz.push_back(part.Vz());
153  fTruePx.push_back(part.Px());
154  fTruePy.push_back(part.Py());
155  fTruePz.push_back(part.Pz());
156 
157  for(const auto& OpHit: *OpHitHandle){
158  fPDS_time.push_back((OpHit.PeakTime()));
159  fOpChan.push_back(OpHit.OpChannel());
160  fPE.push_back(OpHit.PE());
161  }
162  if(fPDS_time.size() > 0) op=true;
163 
164  if(op) fTree->Fill();
165 
166 }
167 
168 
170 {
171  // Implementation of optional member function here.
173 
174  fTree = tFileService->make<TTree>("ProtoDUNE_Evt_Match","ProtoDUNE Matched MC Event Tree");
175 
176  fTree->Branch("fTrueID",&fTrueID);
177  fTree->Branch("fTrue_time",&fTrue_time);
178  fTree->Branch("fTrueStartx",&fTrueStartx);
179  fTree->Branch("fTrueStarty",&fTrueStarty);
180  fTree->Branch("fTrueStartz",&fTrueStartz);
181  fTree->Branch("fTruePx",&fTruePx);
182  fTree->Branch("fTruePy",&fTruePy);
183  fTree->Branch("fTruePz",&fTruePz);
184 
185  fTree->Branch("fPDS_time",&fPDS_time);
186  fTree->Branch("fOpChan",&fOpChan);
187  fTree->Branch("fPE",&fPE);
188 }
189 
std::vector< double > fTrueStartx
void beginJob() override
std::vector< double > fOpChan
PDSPmatchmc(fhicl::ParameterSet const &p)
std::vector< int64_t > fPDS_time
const art::InputTag fOpHitLabel
std::vector< double > fTrueID
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
pure virtual base interface for detector clocks
art framework interface to geometry description
const art::InputTag fGEANTLabel
std::vector< double > fTruePx
std::vector< double > fPE
Access the description of detector geometry.
void analyze(art::Event const &e) override
const double e
std::vector< double > fTrue_time
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
std::vector< double > fTrueStartz
PDSPmatchmc & operator=(PDSPmatchmc const &)=delete
Provides recob::Track data product.
Encapsulate the geometry of an optical detector.
p
Definition: test.py:223
std::vector< double > fTruePz
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
std::vector< double > fTrueStarty
const art::InputTag fMCTruthLabel
std::vector< double > fTruePy