LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
OpDigiAna_module.cc
Go to the documentation of this file.
1 // Christie Chiu and Ben Jones, MIT, 2012
2 //
3 // This is an analyzer module which writes the raw optical
4 // detector pulses for each PMT to an output file
5 //
6 
7 
8 #ifndef OpDigiAna_H
9 #define OpDigiAna_H 1
10 
11 // LArSoft includes
16 
17 // Framework includes
21 #include "fhiclcpp/ParameterSet.h"
29 
30 // ROOT includes
31 #include "TH1.h"
32 #include "THStack.h"
33 #include "TF1.h"
34 #include "TLorentzVector.h"
35 #include "TVector3.h"
36 
37 // C++ Includes
38 #include <map>
39 #include <vector>
40 #include <iostream>
41 #include <cstring>
42 #include <sstream>
43 #include "math.h"
44 #include <climits>
45 
46 namespace opdet {
47 
48  class OpDigiAna : public art::EDAnalyzer{
49  public:
50 
51  // Standard constructor and destructor for an ART module.
53  virtual ~OpDigiAna();
54 
55  // This method is called once, at the start of the job. In this
56  // example, it will define the histogram we'll write.
57  void beginJob();
58 
59  // The analyzer routine, called once per event.
60  void analyze (const art::Event&);
61 
62  private:
63 
64  // The stuff below is the part you'll most likely have to change to
65  // go from this custom example to your own task.
66 
67 
68 
69  // The parameters we'll read from the .fcl file.
70  std::string fInputModule; // Input tag for OpDet collection
71  std::string fInstanceName; // Input tag for OpDet collection
72  float fSampleFreq; // in MHz
73  float fTimeBegin; // in us
74  float fTimeEnd; // in us
75  // short fPEheight; // in ADC counts
77 
78  double fSPEAmp;
79 
82 
83  };
84 
85 }
86 
87 #endif // OpDigiAna_H
88 
89 namespace opdet {
90 
91  //-----------------------------------------------------------------------
92  // Constructor
94  : EDAnalyzer(pset)
95  {
96 
98  fSPEAmp = odp->GetSPECumulativeAmplitude();
99  fTimeBegin = odp->TimeBegin();
100  fTimeEnd = odp->TimeEnd();
101  fSampleFreq = odp->SampleFreq();
102 
103 
104  // Indicate that the Input Module comes from .fcl
105  fInputModule = pset.get<std::string>("InputModule");
106  fInstanceName = pset.get<std::string>("InstanceName");
107  fZeroSupThresh = pset.get<double>("ZeroSupThresh") * fSPEAmp;
108 
109  fMakeBipolarHist = pset.get<bool>("MakeBipolarHist");
110  fMakeUnipolarHist = pset.get<bool>("MakeUnipolarHist");
111 
112 
113  }
114 
115  //-----------------------------------------------------------------------
116  // Destructor
118  {}
119 
120  //-----------------------------------------------------------------------
122  {
123  }
124 
125 
126  //-----------------------------------------------------------------------
127  void OpDigiAna::analyze(const art::Event& evt)
128  {
129 
130  // Create a handle for our vector of pulses
132 
133  // Create string for histogram name
134  char HistName[50];
135 
136 
137  // Read in WaveformHandle
138  evt.getByLabel(fInputModule, fInstanceName, WaveformHandle);
139 
140  // Access ART's TFileService, which will handle creating and writing
141  // histograms for us.
143 
144 
145  std::vector<std::string> histnames;
146 
147  // For every OpDet waveform in the vector given by WaveformHandle
148  for(unsigned int i = 0; i < WaveformHandle->size(); ++i)
149  {
150  // Get OpDetPulse
151  art::Ptr< raw::OpDetPulse > ThePulsePtr(WaveformHandle, i);
152  raw::OpDetPulse ThePulse = *ThePulsePtr;
153 
154  // Make an instance of histogram and its pointer, changing all units to ns
155  // Notice that histogram axis is in ns but binned by 1/64MHz;
156  // appropriate conversions are made from beginning and end time
157  // in us, and frequency in MHz.
158 
159  // Make sure the histogram name is unique since there can be multiple pulses
160  // per event and photo detector
161  unsigned int pulsenum = 0;
162  while (true) {
163  sprintf(HistName, "Event_%d_OpDet_%i_Pulse_%i", evt.id().event(), ThePulse.OpChannel(), pulsenum);
164  auto p = std::find(histnames.begin(), histnames.end(), HistName);
165  if ( p != histnames.end() ) {
166  // Found a duplicate
167  pulsenum++;
168  }
169  else {
170  // Found a unique name
171  histnames.push_back(HistName);
172  break;
173  }
174  }
175 
176 
177 
178  TH1D* PulseHist = nullptr;
179  if(fMakeBipolarHist)
180  {
181  PulseHist= tfs->make<TH1D>(HistName, ";t (ns);",
182  int((fTimeEnd - fTimeBegin) * fSampleFreq),
183  fTimeBegin * 1000.,
184  fTimeEnd * 1000.);
185  }
186 
187  sprintf(HistName, "Event_%d_uni_OpDet_%i_Pulse_%i", evt.id().event(), ThePulse.OpChannel(), pulsenum);
188  TH1D* UnipolarHist = nullptr;
190  {
191  UnipolarHist= tfs->make<TH1D>(HistName, ";t (ns);",
192  int((fTimeEnd - fTimeBegin) * fSampleFreq),
193  fTimeBegin * 1000.,
194  fTimeEnd * 1000.);
195  }
196 
197  for(unsigned int binNum = 0; binNum < ThePulse.Waveform().size(); ++binNum)
198  {
199  // Fill histogram with waveform
200 
201  if(fMakeBipolarHist) PulseHist->SetBinContent( binNum,
202  (double) ThePulse.Waveform()[binNum] );
203  if((binNum>0)&&(fMakeUnipolarHist))
204  {
205  double BinContent = (double) ThePulse.Waveform()[binNum] +
206  (double) UnipolarHist->GetBinContent(binNum-1);
207  if(BinContent>fZeroSupThresh)
208  UnipolarHist->SetBinContent(binNum,BinContent);
209  else
210  UnipolarHist->SetBinContent(binNum,0);
211 
212  }
213 
214  }
215 
216  }
217  }
218 
219 
220 
221 } // namespace opdet
222 
223 namespace opdet {
225 }
std::string fInputModule
unsigned short OpChannel() const
Definition: OpDetPulse.h:60
std::vector< short > & Waveform()
Definition: OpDetPulse.h:59
std::string fInstanceName
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
T get(std::string const &key) const
Definition: ParameterSet.h:231
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
OpDigiAna(const fhicl::ParameterSet &)
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void analyze(const art::Event &)
EventNumber_t event() const
Definition: EventID.h:117
Definition: fwd.h:25
EventID id() const
Definition: Event.h:56
art framework interface to geometry description