LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
FIFOHistogramAna_module.cc
Go to the documentation of this file.
1 // Ben Jones, MIT, 2013
2 //
3 // This simple ana module writes a root file of pulse histograms,
4 // organized by event and channel number
5 //
6 
7 
8 #ifndef FIFOHistogramAna_H
9 #define FIFOHistogramAna_H 1
10 
11 // LArSoft includes
14 
15 // Framework includes
19 #include "fhiclcpp/ParameterSet.h"
27 
28 // ROOT includes
29 #include "TH1.h"
30 #include "THStack.h"
31 #include "TF1.h"
32 #include "TLorentzVector.h"
33 #include "TVector3.h"
34 
35 // C++ Includes
36 #include <map>
37 #include <vector>
38 #include <iostream>
39 #include <cstring>
40 #include <sstream>
41 #include "math.h"
42 #include <climits>
43 
44 namespace opdet {
45 
47  public:
48 
49  // Standard constructor and destructor for an ART module.
51  virtual ~FIFOHistogramAna();
52 
53  // This method is called once, at the start of the job. In this
54  // example, it will define the histogram we'll write.
55  void beginJob();
56 
57  // The analyzer routine, called once per event.
58  void analyze (const art::Event&);
59 
60  private:
61 
62  // The parameters we'll read from the .fcl file.
63  std::string fInputModule; // Input tag for OpDet collection
64 
65  };
66 
67 }
68 
69 #endif // FIFOHistogramAna_H
70 
71 namespace opdet {
72 
73  //-----------------------------------------------------------------------
74  // Constructor
76  : EDAnalyzer(pset)
77  {
78  // Indicate that the Input Module comes from .fcl
79  fInputModule = pset.get<std::string>("InputModule");
80 
81  }
82 
83  //-----------------------------------------------------------------------
84  // Destructor
86  {}
87 
88  //-----------------------------------------------------------------------
90  {
91  }
92 
93 
94  //-----------------------------------------------------------------------
96  {
97 
99 
100  // Create a handle for our vector of pulses
102 
103  // Read in WaveformHandle
104  evt.getByLabel(fInputModule, FIFOChannelHandle);
105 
106  int Run=evt.run();
107  int EID=evt.event();
108 
109  std::stringstream FolderName;
110  FolderName.flush();
111  FolderName<<"run"<<Run<<"_evt"<<EID;
112 
113  art::TFileDirectory evtfolder = tfs->mkdir(FolderName.str().c_str());
114 
115  std::map<int, bool> ChanFolderMade;
116  std::map<uint32_t, int> ChanFolderIndex;
117  std::vector<art::TFileDirectory> ChanFolders;
118 
119 
120  for(size_t i=0; i!=FIFOChannelHandle->size(); ++i)
121  {
122  uint32_t Frame = FIFOChannelHandle->at(i).Frame();
123  uint32_t TimeSlice = FIFOChannelHandle->at(i).TimeSlice();
124  uint32_t Channel = FIFOChannelHandle->at(i).ChannelNumber();
125 
126  if(!ChanFolderMade[Channel])
127  {
128  std::stringstream ChannelLabel;
129  ChannelLabel.flush();
130  ChannelLabel<<"chan"<<Channel;
131  ChanFolderIndex[Channel] = ChanFolders.size();
132  ChanFolders.push_back(evtfolder.mkdir(ChannelLabel.str().c_str()));
133  ChanFolderMade[Channel] = true;
134  }
135 
136  std::stringstream HistName;
137  HistName.flush();
138  HistName<<"frm"<<Frame<<"_"<<"tsl"<<TimeSlice;
139 
140 
141  TH1D * ThisHist = ChanFolders[ChanFolderIndex[Channel] ].make<TH1D>(HistName.str().c_str(),HistName.str().c_str(),FIFOChannelHandle->at(i).size(), float(TimeSlice)-0.0001, float(FIFOChannelHandle->at(i).size())-0.0001+TimeSlice);
142 
143  for(size_t j=0; j!=FIFOChannelHandle->at(i).size(); ++j)
144  {
145  ThisHist->Fill(TimeSlice + j, FIFOChannelHandle->at(i).at(j));
146  }
147  }
148 
149  }
150 
151 
152 
153 } // namespace opdet
154 
155 namespace opdet {
157 }
void analyze(const art::Event &)
TFileDirectory mkdir(std::string const &dir, std::string const &descr="")
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
T get(std::string const &key) const
Definition: ParameterSet.h:231
EventNumber_t event() const
Definition: Event.h:67
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
FIFOHistogramAna(const fhicl::ParameterSet &)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
TCEvent evt
Definition: DataStructs.cxx:5
RunNumber_t run() const
Definition: Event.h:77
art framework interface to geometry description