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
15 #include "fhiclcpp/ParameterSet.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 
32  public:
33 
34  // Standard constructor and destructor for an ART module.
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
54  : EDAnalyzer(pset)
55  {
56  // Indicate that the Input Module comes from .fcl
57  fInputModule = pset.get<std::string>("InputModule");
58 
59  }
60 
61  //-----------------------------------------------------------------------
63  {
64 
66 
67  // Create a handle for our vector of pulses
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 {
124 }
EventNumber_t event() const
Definition: DataViewImpl.cc:85
void analyze(const art::Event &)
std::string string
Definition: nybbler.cc:12
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
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
RunNumber_t run() const
Definition: DataViewImpl.cc:71
FIFOHistogramAna(const fhicl::ParameterSet &)
TCEvent evt
Definition: DataStructs.cxx:7