All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
12 #include "art/Framework/Core/EDAnalyzer.h"
13 #include "art/Framework/Core/ModuleMacros.h"
14 #include "art/Framework/Principal/Event.h"
15 #include "fhiclcpp/ParameterSet.h"
16 #include "art/Framework/Principal/Handle.h"
17 #include "canvas/Persistency/Common/Ptr.h"
18 #include "art/Framework/Services/Registry/ServiceHandle.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.
33  OpDigiAna(const fhicl::ParameterSet&);
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
67  OpDigiAna::OpDigiAna(fhicl::ParameterSet const& pset)
68  : EDAnalyzer(pset)
69  {
70 
71  art::ServiceHandle<OpDigiProperties> odp;
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  //-----------------------------------------------------------------------
90  void OpDigiAna::analyze(const art::Event& evt)
91  {
92 
93  // Create a handle for our vector of pulses
94  art::Handle< std::vector< raw::OpDetPulse > > WaveformHandle;
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.
105  art::ServiceHandle<art::TFileService const> tfs;
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);",
145  int((fTimeEnd - fTimeBegin) * fSampleFreq),
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);",
155  int((fTimeEnd - fTimeBegin) * fSampleFreq),
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 {
187  DEFINE_ART_MODULE(OpDigiAna)
188 }
std::string fInputModule
unsigned short OpChannel() const
Definition: OpDetPulse.h:61
pdgs p
Definition: selectors.fcl:22
const std::vector< short > & Waveform() const
Definition: OpDetPulse.h:59
std::string fInstanceName
OpDigiAna(const fhicl::ParameterSet &)
void analyze(const art::Event &)
art::ServiceHandle< art::TFileService > tfs
TCEvent evt
Definition: DataStructs.cxx:8