LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
OpHitAna_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 OpHitAna_H
9 #define OpHitAna_H 1
10 
11 // LArSoft includes
14 
15 // ART includes.
17 
18 // ROOT classes.
19 class TH1D;
20 class TTree;
21 
22 // C++ includes
23 #include <cstring>
24 #include <vector>
25 
26 namespace opdet {
27 
28  class OpHitAna : public art::EDAnalyzer{
29  public:
30 
31  // Standard constructor and destructor for an ART module.
33  virtual ~OpHitAna();
34 
35  // This method is called once, at the start of the job. In this
36  // example, it will define the histogram we'll write.
37  void beginJob();
38 
39  // The analyzer routine, called once per event.
40  void analyze (const art::Event&);
41 
42  private:
43 
44  // The stuff below is the part you'll most likely have to change to
45  // go from this custom example to your own task.
46 
47  // The parameters we'll read from the .fcl file.
48  std::string fInputModule; // Input tag for OpDet collection
49  float fSampleFreq; // in MHz
50  float fTimeBegin; // in us
51  float fTimeEnd; // in us
52  // short fPEheight; // in ADC counts
53 
54  // Flags to enable or disable output of debugging TH1 / TH2s
58 
59  // Output TTree and its branch variables
60  TTree * fHitTree;
61  Int_t fEventID;
62  Int_t fOpChannel;
63  Float_t fPeakTime;
64  Float_t fNPe;
65 
66 
67  };
68 
69 }
70 
71 #endif // OpHitAna_H
72 
73 
74 
75 
76 // OpHitAna_module.cc
77 
78 // This is a short program required by the ART framework. It enables
79 // a program (OpHitAna, in this case) to be called as a module
80 // from a .fcl file. It is unlikely that you'll have to make any
81 // changes to this file.
82 
83 // Framework includes
85 
86 namespace opdet {
88 }
89 
90 
91 // OpHitAna.cxx
92 
93 // LArSoft includes
97 
98 
99 // Framework includes
101 #include "fhiclcpp/ParameterSet.h"
109 
110 // ROOT includes
111 #include "TH1.h"
112 #include "TTree.h"
113 #include "THStack.h"
114 #include "TLorentzVector.h"
115 #include "TVector3.h"
116 
117 // C++ Includes
118 #include <map>
119 #include <vector>
120 #include <iostream>
121 #include <cstring>
122 #include <sstream>
123 #include "math.h"
124 #include <climits>
125 
126 namespace opdet {
127 
128  //-----------------------------------------------------------------------
129  // Constructor
131  : EDAnalyzer(pset)
132  {
133 
134  // Indicate that the Input Module comes from .fcl
135  fInputModule = pset.get<std::string>("InputModule");
136 
138  fTimeBegin = odp->TimeBegin();
139  fTimeEnd = odp->TimeEnd();
140  fSampleFreq = odp->SampleFreq();
141 
142 
143  fMakeHistPerChannel = pset.get<bool>("MakeHistPerChannel");
144  fMakeHistAllChannels = pset.get<bool>("MakeHistAllChannels");
145  fMakeHitTree = pset.get<bool>("MakeHitTree");
146 
147  // If required, make TTree for output
148 
149  if(fMakeHitTree)
150  {
152  fHitTree = tfs->make<TTree>("HitTree","HitTree");
153  fHitTree->Branch("EventID", &fEventID, "EventID/I");
154  fHitTree->Branch("OpChannel", &fOpChannel, "OpChannel/I");
155  fHitTree->Branch("PeakTime", &fPeakTime, "PeakTime/F");
156  fHitTree->Branch("NPe", &fNPe, "NPe/F");
157  }
158 
159 
160  }
161 
162  //-----------------------------------------------------------------------
163  // Destructor
165  {}
166 
167  //-----------------------------------------------------------------------
169  {
170  }
171 
172 
173  //-----------------------------------------------------------------------
175  {
176 
177  // Create a handle for our vector of pulses
179 
180  // Create string for histogram name
181  char HistName[50];
182 
183 
184  // Read in HitHandle
185  evt.getByLabel(fInputModule, HitHandle);
186 
187  // Access ART's TFileService, which will handle creating and writing
188  // histograms for us.
190 
192  int NOpChannels = geom->NOpChannels();
193 
194  std::vector<TH1D*> HitHist;
195 
196  sprintf(HistName, "Event %d AllOpDets", evt.id().event());
197 
198  TH1D * AllHits = nullptr;
200  {
201  AllHits = tfs->make<TH1D>(HistName, ";t (ns);",
202  int((fTimeEnd - fTimeBegin) * fSampleFreq),
203  fTimeBegin * 1000.,
204  fTimeEnd * 1000.);
205  }
206 
207  for(int i=0; i!=NOpChannels; ++i)
208  {
209 
210  sprintf(HistName, "Event %d OpDet %i", evt.id().event(), i);
211  if(fMakeHistPerChannel) HitHist.push_back ( tfs->make<TH1D>(HistName, ";t (ns);",
212  int((fTimeEnd - fTimeBegin) * fSampleFreq),
213  fTimeBegin * 1000.,
214  fTimeEnd * 1000.));
215 
216  }
217 
218 
219  fEventID = evt.id().event();
220 
221 
222  // For every OpHit in the vector
223  for(unsigned int i = 0; i < HitHandle->size(); ++i)
224  {
225  // Get OpHit
226  art::Ptr< recob::OpHit > TheHitPtr(HitHandle, i);
227  recob::OpHit TheHit = *TheHitPtr;
228 
229  fOpChannel = TheHit.OpChannel();
230  fNPe = TheHit.PE();
231  fPeakTime = TheHit.PeakTime();
232 
233  if(fMakeHitTree)
234  fHitTree->Fill();
235 
237  {
238  if(fOpChannel>int(HitHist.size()))
239  {
240  mf::LogError("OpHitAna")<<"Error : Trying to fill channel out of range, " << fOpChannel;
241  }
242  HitHist[fOpChannel]->Fill(fPeakTime,fNPe);
243  }
244 
245  if(fMakeHistAllChannels) AllHits->Fill(fPeakTime, fNPe);
246 
247  }
248 
249  }
250 
251 } // namespace opdet
252 
253 
double PeakTime() const
Definition: OpHit.h:64
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
unsigned int NOpChannels() const
Number of electronics channels for all the optical detectors.
#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
double PE() const
Definition: OpHit.h:69
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
std::string fInputModule
void analyze(const art::Event &)
EventNumber_t event() const
Definition: EventID.h:117
TCEvent evt
Definition: DataStructs.cxx:5
int OpChannel() const
Definition: OpHit.h:62
EventID id() const
Definition: Event.h:56
OpHitAna(const fhicl::ParameterSet &)
art framework interface to geometry description