All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
wvfAnaicarus_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: wvfAnaicarus
3 // Plugin Type: analyzer (art v2_09_06)
4 // File: wvfAnaicarus_module.cc
5 //
6 // Generated at Wed Feb 7 17:51:39 2018 by Andrea Falcone using cetskelgen
7 // from cetlib version v3_01_03.
8 //
9 // Analyzer to read optical waveforms
10 //
11 // Authors: L. Paulucci and F. Marinho
12 ////////////////////////////////////////////////////////////////////////
13 
14 #include <vector>
15 #include <cmath>
16 #include <memory>
17 #include <string>
18 
19 #include "art/Framework/Core/EDAnalyzer.h"
20 #include "art/Framework/Core/ModuleMacros.h"
21 #include "art/Framework/Principal/Event.h"
22 #include "art/Framework/Principal/Handle.h"
23 #include "art/Framework/Principal/Run.h"
24 #include "art/Framework/Principal/SubRun.h"
25 #include "art_root_io/TFileService.h"
26 #include "canvas/Utilities/InputTag.h"
27 #include "fhiclcpp/ParameterSet.h"
28 #include "messagefacility/MessageLogger/MessageLogger.h"
29 
34 
35 #include "TH1D.h"
36 #include "TFile.h"
37 #include "TTree.h"
38 
39 namespace opdet{
40 
41 class wvfAnaicarus;
42 
43 
44 class wvfAnaicarus : public art::EDAnalyzer {
45 public:
46  explicit wvfAnaicarus(fhicl::ParameterSet const & p);
47  // The compiler-generated destructor is fine for non-base
48  // classes without bare pointers or other resource use.
49 
50  // Plugins should not be copied or assigned.
51  wvfAnaicarus(wvfAnaicarus const &) = delete;
52  wvfAnaicarus(wvfAnaicarus &&) = delete;
53  wvfAnaicarus & operator = (wvfAnaicarus const &) = delete;
54  wvfAnaicarus & operator = (wvfAnaicarus &&) = delete;
55 
56  // Required functions.
57  void analyze(art::Event const & e) override;
58 
59  //Selected optional functions
60  void beginJob() override;
61  void endJob() override;
62 
63 private:
64 
65  size_t fEvNumber;
66  size_t fChNumber;
67  double fSampling;
68  // double fAmp;
69  double fStartTime;
70  double fEndTime;
71 
72  // Declare member data here.
73  std::string fInputModuleName;
74  std::stringstream histname;
75 
76 };
77 
78 
79 wvfAnaicarus::wvfAnaicarus(fhicl::ParameterSet const & p)
80  :
81  EDAnalyzer(p) // ,
82  // More initializers here.
83 {
84  fInputModuleName = p.get< std::string >("InputModule" );
85  fSampling = p.get< double >("Sampling" );
86 
87 }
88 
90 
91 // art::ServiceHandle<art::TFileService> tfs;
92 // fWaveformTree = tfs->make<TTree>("WaveformTree", "event by event info");
93 // fWaveformTree->Branch("event",&fEvNumber,"fEvNumber/I");
94 // fWaveformTree->Branch("ch",&fChNumber,"fChNumber/I");
95 // fWaveformTree->Branch("waveform",&fAmp,"fAmp/D");
96 // fWaveformTree->Branch("time",&fTime,"fTime/D");
97 }
98 
99 
100 void wvfAnaicarus::analyze(art::Event const & e)
101 {
102  // Implementation of required member function here.
103  std::cout << "My module on event #" << e.id().event() << std::endl;
104 
105  art::ServiceHandle<art::TFileService> tfs;
106  fEvNumber = e.id().event();
107 
108  art::Handle< std::vector< raw::OpDetWaveform > > waveHandle;
109  e.getByLabel(fInputModuleName, waveHandle);
110 
111  if(!waveHandle.isValid()){
112  std::cout << Form("Did not find any G4 photons from a producer: %s", "largeant") << std::endl;
113  }
114 
115  std::cout << "Number of photon channel: " <<waveHandle->size() << std::endl;
116 // unsigned int nChannels = pmtHandle->size();
117 
118  for(auto const& wvf : (*waveHandle)){
119  fChNumber = wvf.ChannelNumber();
120  std::cout << "Photon channel: " << fChNumber << std::endl;
121 // std::stringstream histName;
122  histname.str(std::string());
123  histname << "event_" << fEvNumber
124  << "_opchannel_" <<fChNumber;
125 
126  fStartTime = wvf.TimeStamp()/1000; //in us
127  fEndTime = double(wvf.size())/fSampling + fStartTime;
128  fEndTime = fEndTime/1000; //in us
129 
130  //Create a new histogram
131  TH1D *wvfHist = tfs->make< TH1D >(histname.str().c_str(), TString::Format(";t - %f (#mus);",fStartTime), wvf.size(), fStartTime, fEndTime);
132  //if(fChNumber==0){
133 // std::copy(wvf.begin(),wvf.end(),fAmp);
134  for(unsigned int i=0; i<wvf.size();i++){
135  wvfHist->SetBinContent(i+1,(double)wvf[i]);
136 // fAmp = (double)wvf[i];
137  // std::cout << fAmp << fTime << std::endl;
138 // fWaveformTree->Fill();
139  //std::cout << wvf[i] << std::endl;
140  }
141  }
142 }
143 
144 
146 }
147 
148 DEFINE_ART_MODULE(wvfAnaicarus)
149 
150 }
pdgs p
Definition: selectors.fcl:22
void beginJob() override
Simulation objects for optical detectors.
std::stringstream histname
wvfAnaicarus(fhicl::ParameterSet const &p)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
do i e
void analyze(art::Event const &e) override
wvfAnaicarus & operator=(wvfAnaicarus const &)=delete
art::ServiceHandle< art::TFileService > tfs
Tools and modules for checking out the basics of the Monte Carlo.
BEGIN_PROLOG could also be cout