OpDetDigiAnaDUNE_module.cc
Go to the documentation of this file.
1 //==========================================================
2 // OpDetDigiAnaDUNE_module.cc
3 // This analysis module creates histograms
4 // with information from OpDetWaveforms
5 //
6 // Gleb Sinev, Duke, 2015
7 // Based on OpDigiAna_module.cc
8 //==========================================================
9 
10 #ifndef OpDetDigiAnaDUNE_H
11 #define OpDetDigiAnaDUNE_H 1
12 
13 // Framework includes
14 
20 #include "art_root_io/TFileService.h"
21 #include "art_root_io/TFileDirectory.h"
23 #include "fhiclcpp/ParameterSet.h"
24 
25 // LArSoft includes
26 
30 
31 // ROOT includes
32 
33 #include "TH1.h"
34 #include "TTree.h" //Vitor Luzio
35 
36 // C++ includes
37 
38 #include <vector>
39 #include <map>
40 #include <string>
41 #include <sstream>
42 
43 namespace opdet {
44 
46 
47  public:
48 
49  // Standard constructor and destructor for an ART module
51  virtual ~OpDetDigiAnaDUNE();
52 
53  // The analyzer routine, called once per event
54  void analyze(art::Event const&);
55 
56  private:
57 
58  // Parameters we'll read from the fcl-file
59  std::string fInputModule; // Module used to create OpDetWaveforms
60  std::string fInstanceName; // Input tag for OpDetWaveforms collection
61  double fSampleFreq; // Sampling frequency in MHz
62  bool fAnaTree_SSPLED; // Parameter to write a SSP LED Tree
64  int fNEvents;
65 
66 
67  std::vector<double> wf_start;
68  std::vector<int> canal_op;
69  std::vector<double> wf_inicio;
70  std::vector<double> wf_end;
71  std::vector<int> wf_size;
72  TTree *arvore;
73 
74  };
75 
76 }
77 
78 #endif
79 
80 namespace opdet {
81 
83 
84 }
85 
86 namespace opdet {
87 
88  //---------------------------------------------------------------------------
89  // Constructor
91  : EDAnalyzer(pset)
92  , fInputModule { pset.get< std::string >("InputModule") }
93  , fInstanceName { pset.get< std::string >("InstanceName") }
94  , fAnaTree_SSPLED { pset.get< bool >("SSP_LED_AnaTree") }
95  , fMaxEvents { pset.get< int >("MaxEvents", -1) }
96  , fNEvents { 0 }
97 
98  {
99 
100  // Read the fcl-file
101  // Obtain parameters from DetectorClocksService
102  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataForJob();
103  fSampleFreq = clockData.OpticalClock().Frequency();
104 
106 
107 // std::cout<<"Valor bool = "<<fAnaTree_SSPLED<<std::endl;
108 
109  if(fAnaTree_SSPLED){
110  arvore = tfs->make<TTree>("TriggerData","TriggerInfo");
111  arvore->Branch("OpticalCh",&canal_op);
112  arvore->Branch("WfFirstTime",&wf_inicio);
113  arvore->Branch("WfSize",&wf_size);
114  arvore->Branch("Trg_PreTrg",&wf_start);
115  arvore->Branch("WfEnd",&wf_end);
116  }
117 
118  }
119 
120  //---------------------------------------------------------------------------
121  // Destructor
123  {
124  }
125 
126  //---------------------------------------------------------------------------
128  {
129  // Quick exit if not filling tree
130  if (fMaxEvents > 0 && fNEvents > fMaxEvents && !fAnaTree_SSPLED) return;
131 
132  // Map to store how many waveforms are on one optical channel
133  std::map< int, int > mapChannelWF;
134 
135  // Get OpDetWaveforms from the event
137  auto waveformHandle = evt.getHandle< std::vector< raw::OpDetWaveform > >(itag1);
138 
139  // Access ART's TFileService, which will handle creating and writing
140  // histograms for us
142 
143 
144  double firstWaveformTime = -9999;
145 
146  for (auto const& waveform : *waveformHandle)
147  {
148  if (firstWaveformTime < 0) firstWaveformTime = waveform.TimeStamp();
149  }
150 
151 
152  if (fNEvents < 10) {
153  std::cout << "Event #" << evt.id().event() << ", firstTime: " << firstWaveformTime << std::endl;
154  }
155 
156  for (auto const& waveform : *waveformHandle)
157  {
158 
159  int channel = waveform.ChannelNumber();
160 
161  // Implement different end time for waveforms of variable length
162  double startTime = waveform.TimeStamp() - firstWaveformTime;
163  double endTime = double(waveform.size())/fSampleFreq + startTime;
164 
165  if(fAnaTree_SSPLED){
166  canal_op.emplace_back(channel);
167  wf_inicio.emplace_back(firstWaveformTime);
168  wf_start.emplace_back(startTime);
169  wf_end.emplace_back(endTime);
170  wf_size.emplace_back(waveform.size());
171  }
172 
173  // Skip if past max number of events requested
174  if (fMaxEvents > 0 && fNEvents > fMaxEvents) continue;
175 
176  // Make a name for the histogram
177  std::stringstream histName;
178  histName << "event_" << evt.id().event()
179  << "_opchannel_" << channel
180  << "_waveform_" << mapChannelWF[channel];
181  // Increase counter for number of waveforms on this optical channel
182  mapChannelWF[channel]++;
183  // Create a new histogram
184  TH1D *waveformHist = tfs->make< TH1D >(histName.str().c_str(),
185  TString::Format(";t - %f (#mus);",firstWaveformTime),
186  waveform.size(), startTime, endTime);
187 
188  // Copy values from the waveform into the histogram
189  for (size_t tick = 0; tick < waveform.size(); tick++){
190  waveformHist->SetBinContent(tick + 1, waveform[tick]);
191  }
192  }
193 
194  if(fAnaTree_SSPLED){
195  arvore->Fill();
196  canal_op.clear();
197  wf_inicio.clear();
198  wf_start.clear();
199  wf_end.clear();
200  wf_size.clear();
201  }
202 
203  ++fNEvents;
204  }
205 
206 }
std::vector< double > wf_end
std::vector< double > wf_start
Format
Definition: utils.h:7
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
uint8_t channel
Definition: CRTFragment.hh:201
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
void analyze(art::Event const &)
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
std::vector< double > wf_inicio
EventNumber_t event() const
Definition: EventID.h:116
TCEvent evt
Definition: DataStructs.cxx:7
OpDetDigiAnaDUNE(fhicl::ParameterSet const &)
EventID id() const
Definition: Event.cc:34
QTextStream & endl(QTextStream &s)