All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpDetWFDump_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: OpDetWFDump
3 // Plugin Type: analyzer (art v3_01_01)
4 // File: OpDetWFDump_module.cc
5 //
6 // Generated at Tue Feb 12 06:49:35 2019 by Kazuhiro Terao using cetskelgen
7 // from cetlib version v3_05_01.
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include "art/Framework/Core/EDAnalyzer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "canvas/Utilities/InputTag.h"
17 #include "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
19 
27 #include <TTree.h>
28 #include <TFile.h>
29 
30 class OpDetWFDump;
31 
32 class OpDetWFDump : public art::EDAnalyzer {
33 public:
34  explicit OpDetWFDump(fhicl::ParameterSet const& p);
35  // The compiler-generated destructor is fine for non-base
36  // classes without bare pointers or other resource use.
37 
38  // Plugins should not be copied or assigned.
39  OpDetWFDump(OpDetWFDump const&) = delete;
40  OpDetWFDump(OpDetWFDump&&) = delete;
41  OpDetWFDump& operator=(OpDetWFDump const&) = delete;
42  OpDetWFDump& operator=(OpDetWFDump&&) = delete;
43 
44  // Required functions.
45  void analyze(art::Event const& e) override;
46  void beginJob() override;
47  void endJob() override;
48 private:
49 
50  // Declare member data here.
51  TFile* _f;
52  TTree* _wftree;
53  TTree* _hittree;
54  std::vector<float> _wf;
55  int _ch;
56  double _tstart;
57  double _tend;
58  double _tpeak;
59  double _amp;
60  double _area;
61 };
62 
63 
64 OpDetWFDump::OpDetWFDump(fhicl::ParameterSet const& p)
65  : EDAnalyzer{p}, _wftree{nullptr} // ,
66  // More initializers here.
67 {
68  // Call appropriate consumes<>() for any products to be retrieved by this module.
69  _wftree = nullptr;
70 }
71 
73 {
74  if(!_wftree) {
75  _f = TFile::Open("opdetwf.root","RECREATE");
76 
77  _wftree = new TTree("anatree","anatree");
78  //_wftree->Branch("wf","std::vector<float>",&_wf);
79  _wftree->Branch("wf",&_wf);
80  _wftree->Branch("ch",&_ch,"ch/I");
81  _wftree->Branch("tstart",&_tstart,"tstart/D");
82 
83  _hittree = new TTree("hittree","hittree");
84  _hittree->Branch("ch",&_ch,"ch/I");
85  _hittree->Branch("tpeak",&_tpeak,"tpeak/D");
86  _hittree->Branch("amp",&_amp,"amp/D");
87  _hittree->Branch("area",&_area,"area/D");
88  }
89  std::cout<<_wftree<<std::endl;
90 }
91 
93 {
94  if(_wftree) {
95  _f->cd();
96  _wftree->Write();
97  _hittree->Write();
98  _f->Close();
99  }
100 }
101 
102 void OpDetWFDump::analyze(art::Event const& e)
103 {
104  auto const* ts = lar::providerFrom<detinfo::DetectorClocksService>();
105  // Implementation of required member function here.
106  art::Handle< std::vector< raw::OpDetWaveform > > hwf;
107  e.getByLabel("opdaq",hwf);
108 
109  if(!hwf.isValid()){
110  std::cout << "Invalid producer..." << std::endl;
111  }
112 
113  std::cout << "Number of photon channel: " <<hwf->size() << std::endl;
114  // unsigned int nChannels = pmtHandle->size();
115  auto geop = lar::providerFrom<geo::Geometry>();
116 
117  std::cout << geop->Ncryostats() << " cryostats" << std::endl;
118 
119  for(auto const& opwf : (*hwf)) {
120  std::cout << opwf.ChannelNumber() << " ... " << opwf.size() << std::endl;
121  _wf.resize(opwf.size());
122  //std::cout<<_wftree<<std::endl;
123  for(size_t i=0; i<_wf.size(); ++i) { _wf.at(i) = opwf.at(i); }
124  _ch=opwf.ChannelNumber();
125  _tstart=opwf.TimeStamp();
126  _wftree->Fill();
127  }
128 
129  std::cout << (*hwf)[0].TimeStamp() << " ... " << ts->TriggerTime() << " ... " << ts->BeamGateTime() << " ... " << ts->G4ToElecTime(0.) << std::endl;
130 
131  art::Handle< std::vector< recob::OpHit> > hhit;
132  e.getByLabel("opreco",hhit);
133 
134  if(!hhit.isValid())
135  std::cout << "aho" << std::endl;
136 
137  for(auto const& oph : (*hhit)) {
138  _ch=oph.OpChannel();
139  _tpeak = oph.PeakTime();
140  _amp = oph.Amplitude();
141  _area = oph.Area();
142  _hittree->Fill();
143  }
144 
145 }
146 
147 DEFINE_ART_MODULE(OpDetWFDump)
void beginJob() override
pdgs p
Definition: selectors.fcl:22
OpDetWFDump(fhicl::ParameterSet const &p)
void endJob() override
Simulation objects for optical detectors.
OpDetWFDump & operator=(OpDetWFDump const &)=delete
object containing MC truth information necessary for making RawDigits and doing back tracking ...
do i e
Tools and modules for checking out the basics of the Monte Carlo.
art framework interface to geometry description
BEGIN_PROLOG could also be cout
void analyze(art::Event const &e) override
std::vector< float > _wf