All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // 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 "art/Framework/Services/Registry/ServiceHandle.h"
18 #include "art_root_io/TFileService.h"
19 #include "art_root_io/TFileDirectory.h"
20 
21 // ROOT includes
22 #include "TH1.h"
23 
24 // C++ Includes
25 #include <map>
26 #include <cstring>
27 #include <sstream>
28 
29 namespace opdet {
30 
31  class FIFOHistogramAna : public art::EDAnalyzer{
32  public:
33 
34  // Standard constructor and destructor for an ART module.
35  FIFOHistogramAna(const fhicl::ParameterSet&);
36 
37  // The analyzer routine, called once per event.
38  void analyze (const art::Event&);
39 
40  private:
41 
42  // The parameters we'll read from the .fcl file.
43  std::string fInputModule; // Input tag for OpDet collection
44 
45  };
46 
47 }
48 
49 namespace opdet {
50 
51  //-----------------------------------------------------------------------
52  // Constructor
53  FIFOHistogramAna::FIFOHistogramAna(fhicl::ParameterSet const& pset)
54  : EDAnalyzer(pset)
55  {
56  // Indicate that the Input Module comes from .fcl
57  fInputModule = pset.get<std::string>("InputModule");
58 
59  }
60 
61  //-----------------------------------------------------------------------
62  void FIFOHistogramAna::analyze(const art::Event& evt)
63  {
64 
65  art::ServiceHandle<art::TFileService> tfs;
66 
67  // Create a handle for our vector of pulses
68  art::Handle< std::vector< optdata::FIFOChannel > > FIFOChannelHandle;
69 
70  // Read in WaveformHandle
71  evt.getByLabel(fInputModule, FIFOChannelHandle);
72 
73  int Run=evt.run();
74  int EID=evt.event();
75 
76  std::stringstream FolderName;
77  FolderName.flush();
78  FolderName<<"run"<<Run<<"_evt"<<EID;
79 
80  art::TFileDirectory evtfolder = tfs->mkdir(FolderName.str().c_str());
81 
82  std::map<int, bool> ChanFolderMade;
83  std::map<uint32_t, int> ChanFolderIndex;
84  std::vector<art::TFileDirectory> ChanFolders;
85 
86 
87  for(size_t i=0; i!=FIFOChannelHandle->size(); ++i)
88  {
89  uint32_t Frame = FIFOChannelHandle->at(i).Frame();
90  uint32_t TimeSlice = FIFOChannelHandle->at(i).TimeSlice();
91  uint32_t Channel = FIFOChannelHandle->at(i).ChannelNumber();
92 
93  if(!ChanFolderMade[Channel])
94  {
95  std::stringstream ChannelLabel;
96  ChannelLabel.flush();
97  ChannelLabel<<"chan"<<Channel;
98  ChanFolderIndex[Channel] = ChanFolders.size();
99  ChanFolders.push_back(evtfolder.mkdir(ChannelLabel.str().c_str()));
100  ChanFolderMade[Channel] = true;
101  }
102 
103  std::stringstream HistName;
104  HistName.flush();
105  HistName<<"frm"<<Frame<<"_"<<"tsl"<<TimeSlice;
106 
107 
108  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);
109 
110  for(size_t j=0; j!=FIFOChannelHandle->at(i).size(); ++j)
111  {
112  ThisHist->Fill(TimeSlice + j, FIFOChannelHandle->at(i).at(j));
113  }
114  }
115 
116  }
117 
118 
119 
120 } // namespace opdet
121 
122 namespace opdet {
123  DEFINE_ART_MODULE(FIFOHistogramAna)
124 }
void analyze(const art::Event &)
FIFOHistogramAna(const fhicl::ParameterSet &)
art::ServiceHandle< art::TFileService > tfs
TCEvent evt
Definition: DataStructs.cxx:8