AdcEventViewer.h
Go to the documentation of this file.
1 // AdcEventViewer.h
2 //
3 // David Adams
4 // August 2018
5 //
6 // ADC tool to extract and display event-level information.
7 //
8 // Configuration:
9 // LogLevel - Logging level: 0=none, 1=init, 2=call, ...
10 // EventHists - Array of string histogram specifiers with format "name:nbin:xmin:xmax"
11 // The field name must contain the histogramed variable. Allowed values:
12 // nfemb - # FEMBs with data
13 // rmPedPower - sqrt(<(ped noise)^2>)
14 // meanPed - <ped>
15 // EventGraphs - Array of graph specifiers with format xname:xmin:xmax:yname:ymin:ymax
16 // The name fields may contain any of the above plus
17 // event - Event number
18 // clock - Timing clock count
19 // For both histograms and graphs min > max gives auto scaling
20 // If xmax > xmin the displayed range is [min, xmax]
21 // For graphs, if xmax == xmin and xmax >= 0, plotted range is [dmin-xmax, dmax+xmax]
22 // ChannelRanges - If this is not empty, then a separate histogram an graph plots
23 // are made for each channel range. Otherwise all channels are included.
24 // The tool channelRanges is used to map the names in this list to ranges.
25 // Special name "all" or "" plots all channels with label "All".
26 // ChannelRangeLabel - Label for channel ranges. May include %XXX% for
27 // XXX = CRLABEL to replace with cr.label()
28 // XXX = CRLABEL1 to replace with cr.label(1)
29 // XXX = CRLABEL2 to replace with cr.label(2)
30 // ClockUnit - Unit for plotting clock counts: tick, ktick or Mtick
31 // ClockRate - # clock ticks per second. Used to conver to time.
32 //
33 // Histogram specifiers are string with the form
34 // Graph specifiers are xnam:xmin:xmax:ynam:ymin:ymax
35 // where [dmin, dmax] are the graph data limits.
36 #ifndef AdcEventViewer_H
37 #define AdcEventViewer_H
38 
40 #include "fhiclcpp/ParameterSet.h"
43 #include <iostream>
44 
46 
47 public:
48 
49  using Index = unsigned int;
50  using IndexVector = std::vector<Index>;
51  using IndexSet = std::set<Index>;
52  using LongIndex = unsigned long;
53  using LongIndexVector = std::vector<LongIndex>;
54  using Name = std::string;
55  using NameVector = std::vector<Name>;
56  using HistVector = std::vector<TH1*>;
57  using HistMap = std::map<Name, TH1*>;
58  using NameMap = std::map<Name, Name>;
59  using FloatVector = std::vector<float>;
60  using GraphVector = std::vector<TGraph*>;
61  using IndexRangeVector = std::vector<IndexRange>;
62 
63  // Subclass that associates a variable name with a histogram.
64  // vary != "" ==> 2D histo
65  class HistInfo {
66  public:
67  TH1* ph = nullptr;
70  };
71 
72  using HistInfoMap = std::map<Name, HistInfo>;
73 
74  // Subclass that describes a graph.
75  struct GraphInfo {
80  float xmin;
81  float xmax;
82  float xoff; // display range is (xmin-xoff, xmax+xoff);
87  float ymin;
88  float ymax;
89  float yoff;
90  GraphInfo() { };
91  GraphInfo(Name avarx, Name axlab, Name axunit, float axmin, float axmax, float axoff,
92  Name avary, Name aylab, Name ayunit, float aymin, float aymax, float ayoff)
93  : varx(avarx), xlab(axlab), xunit(axunit), xmin(axmin), xmax(axmax), xoff(axoff),
94  vary(avary), ylab(aylab), yunit(ayunit), ymin(aymin), ymax(aymax), yoff(ayoff) { }
95  // Add value to vector if name matches.
96  void add(Name var, float val) {
97  if ( var == varx ) xvals.push_back(val);
98  if ( var == vary ) yvals.push_back(val);
99  }
100  // Return axis labels.
101  Name xAxisLabel() const {
102  return xlab + (xunit.size() ? " [" + xunit + "]" : "");
103  }
104  Name yAxisLabel() const {
105  return ylab + (yunit.size() ? " [" + yunit + "]" : "");
106  }
107  };
108  using GraphInfoVector = std::vector<GraphInfo>;
109 
110  // This subclass carries state data for one channel range.
112  public:
113  IndexSet fembIDSet; // FEMBs for ths event.
114  Index nchan =0; // # channels processed for this event
115  float pedSum =0.0; // Sum over pedestals
116  float pedPower =0.0; // Sum over (pedestal noise)^2
117  HistVector hists; // Monitoring histograms.
118  GraphInfoVector graphs; // Monitoring graphs.
119  };
120 
121  using ChannelRangeStates = std::map<Name,ChannelRangeState>;
122 
123  // This subclass carries the state for this tool, i.e. data that can change
124  // after initialization.
125  class State {
126  public:
127  Index beginEventCount =0; // # calls to beginEvent
128  Index endEventCount =0; // # calls to endEvent
129  DuneEventInfo eventInfo; // Event info
130  IndexVector events; // Events in processed order.
131  LongIndexVector clocks; // Timing clocks in processed order.
132  LongIndex firstClock =0; // First timing clock.
133  LongIndex minClock =0; // Minimum timing clock.
134  IndexSet eventSet; // Events ordered.
135  IndexSet runSet; // Events ordered.
136  Index ngroup =0; // # groups processed for this event
138  // Methods.
139  bool haveEvent() const { return eventInfo.isValid(); } // Is there a current event?
140  Index run() const { return eventInfo.run; } // Current run number.
141  Index event() const { return eventInfo.event; } // Current event.
142  LongIndex clock() const { return eventInfo.triggerClock; } // Current timing clock.
143  std::string runString() const; // Run string in DuneEventInfo format for current or run from set.
144  };
145 
146  using StatePtr = std::shared_ptr<State>;
147 
149 
150  ~AdcEventViewer() override;
151 
152  // AdcChannelTool methods.
153  DataMap beginEvent(const DuneEventInfo& devt) const override;
154  DataMap endEvent(const DuneEventInfo& devt) const override;
155  DataMap view(const AdcChannelData& acd) const override;
156  DataMap viewMap(const AdcChannelDataMap& acds) const override;
157  bool updateWithView() const override { return true; }
158 
159  // Return the state.
160  State& state() const { return *m_state; }
161 
162  // Return the state for a channel range.
163  ChannelRangeState& crstate(Name crn) const;
164 
165  // Initialize the state for a new event.
166  void beginEventState(const DuneEventInfo& devt) const;
167 
168  // End current event in state.
169  void endEventState(const DuneEventInfo& devt) const;
170 
171  // Print a report.
172  void printReport() const;
173 
174  // Display the histograms, i.e create pngs.
175  void displayHists() const;
176 
177  // Display the graphs, i.e create pngs.
178  void displayGraphs() const;
179 
180 private:
181 
182  // Configuration data.
189  double m_ClockRate;
190 
191  // Channel ranges.
193 
194  // Shared pointer so we can make sure only one reference is out at a time.
196 
197 };
198 
199 
200 #endif
std::map< Name, TH1 * > HistMap
GraphInfo(Name avarx, Name axlab, Name axunit, float axmin, float axmax, float axoff, Name avary, Name aylab, Name ayunit, float aymin, float aymax, float ayoff)
std::map< Name, Name > NameMap
NameVector m_EventHists
void add(Name var, float val)
void printReport() const
LongIndex clock() const
unsigned int Index
std::string string
Definition: nybbler.cc:12
unsigned long LongIndex
DataMap endEvent(const DuneEventInfo &devt) const override
std::vector< Index > IndexVector
NameVector m_EventGraphs
std::vector< float > FloatVector
bool updateWithView() const override
std::map< Name, HistInfo > HistInfoMap
std::map< Name, ChannelRangeState > ChannelRangeStates
DataMap view(const AdcChannelData &acd) const override
void displayGraphs() const
DuneEventInfo eventInfo
DataMap beginEvent(const DuneEventInfo &devt) const override
std::vector< TH1 * > HistVector
AdcEventViewer(fhicl::ParameterSet const &ps)
ChannelRangeStates crstates
State & state() const
static constexpr double ps
Definition: Units.h:99
LongIndexVector clocks
bool isValid() const
Definition: DuneEventInfo.h:65
void beginEventState(const DuneEventInfo &devt) const
Index event() const
ChannelRangeState & crstate(Name crn) const
NameVector m_ChannelRanges
IndexRangeVector m_crs
int var
Definition: 018_def.c:9
void displayHists() const
std::vector< LongIndex > LongIndexVector
std::vector< GraphInfo > GraphInfoVector
void endEventState(const DuneEventInfo &devt) const
std::vector< IndexRange > IndexRangeVector
~AdcEventViewer() override
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
std::shared_ptr< State > StatePtr
DataMap viewMap(const AdcChannelDataMap &acds) const override
std::string Name
LongIndex triggerClock
Definition: DuneEventInfo.h:27
bool haveEvent() const
std::vector< TGraph * > GraphVector
std::vector< Name > NameVector
std::set< Index > IndexSet