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 // LArSoft includes
11 
12 // Framework includes
18 #include "art_root_io/TFileService.h"
20 #include "fhiclcpp/ParameterSet.h"
22 
23 // ROOT includes
24 #include "TH1D.h"
25 #include "TLorentzVector.h"
26 #include "TTree.h"
27 
28 // C++ Includes
29 #include "math.h"
30 
31 namespace opdet {
32 
33  class OpHitAna : public art::EDAnalyzer{
34  public:
35 
36  // Standard constructor and destructor for an ART module.
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 
72 // OpHitAna_module.cc
73 
74 // This is a short program required by the ART framework. It enables
75 // a program (OpHitAna, in this case) to be called as a module
76 // from a .fcl file. It is unlikely that you'll have to make any
77 // changes to this file.
78 
79 namespace opdet {
81 }
82 
83 namespace opdet {
84 
85  //-----------------------------------------------------------------------
86  // Constructor
88  : EDAnalyzer(pset)
89  {
90 
91  // Indicate that the Input Module comes from .fcl
92  fInputModule = pset.get<std::string>("InputModule");
93 
95  fTimeBegin = odp->TimeBegin();
96  fTimeEnd = odp->TimeEnd();
97  fSampleFreq = odp->SampleFreq();
98 
99 
100  fMakeHistPerChannel = pset.get<bool>("MakeHistPerChannel");
101  fMakeHistAllChannels = pset.get<bool>("MakeHistAllChannels");
102  fMakeHitTree = pset.get<bool>("MakeHitTree");
103 
104  // If required, make TTree for output
105 
106  if(fMakeHitTree)
107  {
109  fHitTree = tfs->make<TTree>("HitTree","HitTree");
110  fHitTree->Branch("EventID", &fEventID, "EventID/I");
111  fHitTree->Branch("OpChannel", &fOpChannel, "OpChannel/I");
112  fHitTree->Branch("PeakTime", &fPeakTime, "PeakTime/F");
113  fHitTree->Branch("NPe", &fNPe, "NPe/F");
114  }
115 
116 
117  }
118 
119  //-----------------------------------------------------------------------
121  {
122 
123  // Create a handle for our vector of pulses
125 
126  // Create string for histogram name
127  char HistName[50];
128 
129 
130  // Read in HitHandle
131  evt.getByLabel(fInputModule, HitHandle);
132 
133  // Access ART's TFileService, which will handle creating and writing
134  // histograms for us.
136 
138  int NOpChannels = geom->NOpChannels();
139 
140  std::vector<TH1D*> HitHist;
141 
142  sprintf(HistName, "Event %d AllOpDets", evt.id().event());
143 
144  TH1D * AllHits = nullptr;
146  {
147  AllHits = tfs->make<TH1D>(HistName, ";t (ns);",
149  fTimeBegin * 1000.,
150  fTimeEnd * 1000.);
151  }
152 
153  for(int i=0; i!=NOpChannels; ++i)
154  {
155 
156  sprintf(HistName, "Event %d OpDet %i", evt.id().event(), i);
157  if(fMakeHistPerChannel) HitHist.push_back ( tfs->make<TH1D>(HistName, ";t (ns);",
158  int((fTimeEnd - fTimeBegin) * fSampleFreq),
159  fTimeBegin * 1000.,
160  fTimeEnd * 1000.));
161 
162  }
163 
164 
165  fEventID = evt.id().event();
166 
167 
168  // For every OpHit in the vector
169  for(unsigned int i = 0; i < HitHandle->size(); ++i)
170  {
171  // Get OpHit
172  art::Ptr< recob::OpHit > TheHitPtr(HitHandle, i);
173  recob::OpHit TheHit = *TheHitPtr;
174 
175  fOpChannel = TheHit.OpChannel();
176  fNPe = TheHit.PE();
177  fPeakTime = TheHit.PeakTime();
178 
179  if(fMakeHitTree)
180  fHitTree->Fill();
181 
183  {
184  if(fOpChannel>int(HitHist.size()))
185  {
186  mf::LogError("OpHitAna")<<"Error : Trying to fill channel out of range, " << fOpChannel;
187  }
188  HitHist[fOpChannel]->Fill(fPeakTime,fNPe);
189  }
190 
191  if(fMakeHistAllChannels) AllHits->Fill(fPeakTime, fNPe);
192 
193  }
194 
195  }
196 
197 } // namespace opdet
std::string string
Definition: nybbler.cc:12
double PeakTime() const
Definition: OpHit.h:64
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
unsigned int NOpChannels() const
Number of electronics channels for all the optical detectors.
art framework interface to geometry description
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
double PE() const
Definition: OpHit.h:69
Index NOpChannels(Index)
std::string fInputModule
void analyze(const art::Event &)
EventNumber_t event() const
Definition: EventID.h:116
TCEvent evt
Definition: DataStructs.cxx:7
int OpChannel() const
Definition: OpHit.h:62
EventID id() const
Definition: Event.cc:34
OpHitAna(const fhicl::ParameterSet &)