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 // LArSoft includes
10 
11 // Framework includes
15 #include "fhiclcpp/ParameterSet.h"
19 #include "art_root_io/TFileService.h"
20 
21 // ROOT includes
22 #include "TH1.h"
23 
24 // C++ Includes
25 #include <algorithm>
26 
27 namespace opdet {
28 
29  class OpDigiAna : public art::EDAnalyzer{
30  public:
31 
32  // Standard constructor and destructor for an ART module.
34 
35  // The analyzer routine, called once per event.
36  void analyze (const art::Event&);
37 
38  private:
39 
40  // The stuff below is the part you'll most likely have to change to
41  // go from this custom example to your own task.
42 
43 
44 
45  // The parameters we'll read from the .fcl file.
46  std::string fInputModule; // Input tag for OpDet collection
47  std::string fInstanceName; // Input tag for OpDet collection
48  float fSampleFreq; // in MHz
49  float fTimeBegin; // in us
50  float fTimeEnd; // in us
51  // short fPEheight; // in ADC counts
53 
54  double fSPEAmp;
55 
58 
59  };
60 
61 }
62 
63 namespace opdet {
64 
65  //-----------------------------------------------------------------------
66  // Constructor
68  : EDAnalyzer(pset)
69  {
70 
72  fSPEAmp = odp->GetSPECumulativeAmplitude();
73  fTimeBegin = odp->TimeBegin();
74  fTimeEnd = odp->TimeEnd();
75  fSampleFreq = odp->SampleFreq();
76 
77 
78  // Indicate that the Input Module comes from .fcl
79  fInputModule = pset.get<std::string>("InputModule");
80  fInstanceName = pset.get<std::string>("InstanceName");
81  fZeroSupThresh = pset.get<double>("ZeroSupThresh") * fSPEAmp;
82 
83  fMakeBipolarHist = pset.get<bool>("MakeBipolarHist");
84  fMakeUnipolarHist = pset.get<bool>("MakeUnipolarHist");
85 
86 
87  }
88 
89  //-----------------------------------------------------------------------
91  {
92 
93  // Create a handle for our vector of pulses
95 
96  // Create string for histogram name
97  char HistName[50];
98 
99 
100  // Read in WaveformHandle
101  evt.getByLabel(fInputModule, fInstanceName, WaveformHandle);
102 
103  // Access ART's TFileService, which will handle creating and writing
104  // histograms for us.
106 
107 
108  std::vector<std::string> histnames;
109 
110  // For every OpDet waveform in the vector given by WaveformHandle
111  for(unsigned int i = 0; i < WaveformHandle->size(); ++i)
112  {
113  // Get OpDetPulse
114  art::Ptr< raw::OpDetPulse > ThePulsePtr(WaveformHandle, i);
115  raw::OpDetPulse ThePulse = *ThePulsePtr;
116 
117  // Make an instance of histogram and its pointer, changing all units to ns
118  // Notice that histogram axis is in ns but binned by 1/64MHz;
119  // appropriate conversions are made from beginning and end time
120  // in us, and frequency in MHz.
121 
122  // Make sure the histogram name is unique since there can be multiple pulses
123  // per event and photo detector
124  unsigned int pulsenum = 0;
125  while (true) {
126  sprintf(HistName, "Event_%d_OpDet_%i_Pulse_%i", evt.id().event(), ThePulse.OpChannel(), pulsenum);
127  auto p = std::find(histnames.begin(), histnames.end(), HistName);
128  if ( p != histnames.end() ) {
129  // Found a duplicate
130  pulsenum++;
131  }
132  else {
133  // Found a unique name
134  histnames.push_back(HistName);
135  break;
136  }
137  }
138 
139 
140 
141  TH1D* PulseHist = nullptr;
142  if(fMakeBipolarHist)
143  {
144  PulseHist= tfs->make<TH1D>(HistName, ";t (ns);",
146  fTimeBegin * 1000.,
147  fTimeEnd * 1000.);
148  }
149 
150  sprintf(HistName, "Event_%d_uni_OpDet_%i_Pulse_%i", evt.id().event(), ThePulse.OpChannel(), pulsenum);
151  TH1D* UnipolarHist = nullptr;
153  {
154  UnipolarHist= tfs->make<TH1D>(HistName, ";t (ns);",
156  fTimeBegin * 1000.,
157  fTimeEnd * 1000.);
158  }
159 
160  for(unsigned int binNum = 0; binNum < ThePulse.Waveform().size(); ++binNum)
161  {
162  // Fill histogram with waveform
163 
164  if(fMakeBipolarHist) PulseHist->SetBinContent( binNum,
165  (double) ThePulse.Waveform()[binNum] );
166  if((binNum>0)&&(fMakeUnipolarHist))
167  {
168  double BinContent = (double) ThePulse.Waveform()[binNum] +
169  (double) UnipolarHist->GetBinContent(binNum-1);
170  if(BinContent>fZeroSupThresh)
171  UnipolarHist->SetBinContent(binNum,BinContent);
172  else
173  UnipolarHist->SetBinContent(binNum,0);
174 
175  }
176 
177  }
178 
179  }
180  }
181 
182 
183 
184 } // namespace opdet
185 
186 namespace opdet {
188 }
std::string fInputModule
std::string string
Definition: nybbler.cc:12
unsigned short OpChannel() const
Definition: OpDetPulse.h:61
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
const std::vector< short > & Waveform() const
Definition: OpDetPulse.h:59
std::string fInstanceName
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
p
Definition: test.py:223
OpDigiAna(const fhicl::ParameterSet &)
void analyze(const art::Event &)
EventNumber_t event() const
Definition: EventID.h:116
TCEvent evt
Definition: DataStructs.cxx:7
Definition: fwd.h:31
EventID id() const
Definition: Event.cc:34