AdcTickModViewer.h
Go to the documentation of this file.
1 // AdcTickModViewer.h
2 
3 // David Adams
4 // June 2018
5 //
6 // Tool to view and fit ADC tickmods.
7 //
8 // A tickmod is the tick number modulus a specified period, e.g. that
9 // from a pulser run.
10 //
11 // If FitRmsMin < FitRmsMax, the the RMS is constrained to the range
12 // (FitRmsMin, FitRmsMax) in the fit.
13 //
14 // Configuration:
15 // LogLevel - 0=silent, 1=init, 2=each event, >2=more
16 // TickModPeriod - Period for tickmods [ticks], i.e. # ticks when wf repeats
17 // TimeOffsetTool - Name of the tool used to get the tick offset.
18 // If blank, no offset is applied.
19 // Otherwise integral offset only is used. Unit must be tick.
20 // FitSigmaMin: Lower limit for sigma in SCM fit of tickmod.
21 // FitSigmaMax: Upper limit for sigma in SCM fit of tickmod.
22 // HistName: Name for the histogram.
23 // HistTitle: Title for the histogram.
24 // HistChannelCount: # channels shown in histogram
25 // AllPlotFileName: If nonblank, histograms for all tickmods are displayed in these
26 // files. The field %TICKMOD% is replaced with the first tickmod.
27 // MinPlotFileName: If nonblank, histograms for tickmods near the min ADC count are
28 // displayed in these files.
29 // MaxPlotFileName: If nonblank, histograms for tickmods near the max ADC count are
30 // displayed in these files.
31 // PhasePlotFileName: If nonblank, plots of phase vs. peak tickmod are displayed.
32 // PhaseVariable: Variable that appears on y-axis of phase plots: phase, event, tick0, nchan
33 // RootFileName: If nonblank, histogram is copied to this file.
34 // TreeFileName: If nonblank, a tickmod tree is created in this file.
35 // PlotChannels: If not empty, only the listed channels are plotted.
36 // PlotSizeX, PlotSizeY: Size in pixels of the plot files.
37 // Root default (700x500?) is used if either is zero.
38 // PlotShowFit: Flag indicating how fit should be displayed.
39 // >= 1: Show final fit
40 // >= 2: Show starting fit function
41 // PlotSplitX: If this is nonzero, plots are created in updateMap (not update)
42 // and the drawing canvas is split NY x NX where NX = PlotSplitX.
43 // If PlotSplitX == 0, one canvas/plot is created in update.
44 // PlotSplitY: If PlotSplitY > 0, then the above NY = PlotSplitY. Otherwise
45 // NY = PlotSplitX. No effect if PlotSplitX == 0.
46 // and up to that many plots are shown on the screen.
47 // PlotFrequency: 0 - Only make plots at end of job (in dtor).
48 // 1 - Make plots every event. Only allowed for Grouping = channel.
49 // PhaseGrouping - Grouping at which phase plots are produced:
50 // channel or femb
51 // PhasePlotSizeX: As above but for phase plots.
52 // PhasePlotSizeY: As above but for phase plots.
53 // PhasePlotSplitX: As above but for phase plots.
54 // PhasePlotSplitY: As above but for phase plots.
55 //
56 // Tools:
57 // adcStringBuilder is used to make the following
58 // substitutions in the names and title:
59 // %RUN% --> run number
60 // %SUBRUN% --> subrun number
61 // %EVENT% --> event number
62 // %CHAN% --> channel number
63 // %TICKMOD% --> tickmod (or Min or Max for those plots)
64 //
65 // The single-channel methods return a data map with the following:
66 // tmCount: - The tickmod period, e.g. 497
67 // tmPlotCount: - The number of tickmod plots
68 // tmHists: - The processed (not narrowed) tickmod histograms for this channel
69 
70 #ifndef AdcTickModViewer_H
71 #define AdcTickModViewer_H
72 
74 #include "fhiclcpp/ParameterSet.h"
77 #include "TH1.h"
78 #include "TGraph.h"
79 #include <string>
80 #include <vector>
81 #include <memory>
82 
84 class TimeOffsetTool;
85 class TFile;
86 class TTree;
87 class TPadManipulator;
88 
89 class AdcTickModViewer : public TpcDataTool {
90 
91 public:
92 
93  using Index = unsigned int;
94  using IndexVector = std::vector<Index>;
95  using IndexMap = std::map<Index, Index>;
96  using IndexVectorMap = std::map<Index, IndexVector>;
97  using Name = std::string;
98  using HistPtr = std::shared_ptr<TH1>;
99  using HistVector = std::vector<HistPtr>;
100  using HistVectorMap = std::map<Index, HistVector>;
101  using GraphPtr = std::shared_ptr<TGraph>;
102  using GraphMap = std::map<Index, GraphPtr>;
103  using FloatVector = std::vector<float>;
104  using FloatVVector = std::vector<FloatVector>;
105  using FloatVVectorMap = std::map<Index, FloatVVector>;
106 
108 
110 
111  DataMap viewMap(const AdcChannelDataMap& acds) const override;
112  DataMap view(const AdcChannelData& acd) const override;
113  bool updateWithView() const override { return true; }
114 
115 private: //data
116 
117  // Configuration data.
145 
146  // ADC string tool.
148 
149  // Tick offset tool.
151 
152  // Derived data.
157 
158  bool m_plotAll;
159  bool m_plotMin;
160  bool m_plotMax;
161  bool m_plotAny;
164 
167 
168  // Number of timing phases.
169  // This is for 50 MHz timer and 2 MHz readout.
170  // May wat to make this a config param.
172 
173  // This subclass carries the state for this tool, i.e. data that can change
174  // after initialization.
175  class State {
176  public:
177  // Tickmod Histograms mapped by channel.
178  // Full hists have 4096 channels.
179  // Proc hists have the region from the sticky code anlysis.
182  // Vectors of event numbers and tick0s.
186  // Tickmod position of the ADC max for each channel, phase variable and event.
187  // MaxTickMods[icha][ivar] is the vector of tickmod peak positions for channel icha
188  // and variable index ivar.
190  // Phase graph for each channel/femb.
192  // Map of empty ADCchannel objects indexed by channel.
194  // Current channel ADC channel data object. Used to build plot names.
197  // Phase index, e.g. femb, for each channel.
199  // Vector of channels for each phase index.
201  // Tree.
203  TFile* pfile =nullptr;
204  TTree* tickmodTree =nullptr;
205  // Tick offset for the job.
206  bool haveTick0Job = false;
207  double tick0Job = 0.0;
208  // Accounting.
211  };
212 
213  // Return the state.
214  using StatePtr = std::shared_ptr<State>;
216  State& state() const { return *m_state; }
217 
218 private:
219 
220  // Set and return the grouping index from ADC data.
221  // Grouping = channel: channel number
222  // Grouping = femb: FEMB number
223  // Otherwise 0
224  // The description of the event and channel is recorded the first time
225  // each index is retrieved.
226  void setChannelData(const AdcChannelData& acd) const;
227 
228  // Set the channel index.
229  // The current ADC data is set based on the index.
230  Index setChannel(Index igran) const;
231 
232  // Clear the current channel index and ADC data.
233  void clearChannelIndex() const;
234 
235  // Retreve the current channel index.
236  Index getChannelIndex() const;
237 
238  // Make replacements in a name.
239  Name nameReplace(Name name, const AdcChannelData& acd, Index itkm) const;
240 
241  // Process a tickmod for channel.
242  // Fills the tickmod histogram and the max tickmod vector.
243  // Returns the mean signal for the tickmod in sigMean.
244  int processChannelTickMod(const AdcChannelData& acd, Index itkm0,
245  Index itkm, float& sigMean) const;
246 
247  // Process the accumulated histogram for the current channel/femb.
248  // StickyCodeMetrics is used to create limited-range histogram and evaluate
249  // sticky code metrics for that region.
250  int processAccumulatedChannel(Index& nplot) const;
251 
252  // Process the accumulated histogram for all channels.
253  int processAccumulation(Index& nplot) const;
254 
255  // Create plot files for the tickmod histograms for the current channel/femb.
256  // nplot - # plot files created
257  int makeTickModPlots(Index& nplot) const;
258 
259  // Create the phase graphs.
260  int makePhaseGraphs() const;
261 
262  // Create the phase plots.
263  int plotPhaseGraphs() const;
264 
265 };
266 
267 
268 #endif
static QCString name
Definition: declinfo.cpp:673
void clearChannelIndex() const
std::map< Index, FloatVVector > FloatVVectorMap
std::shared_ptr< TGraph > GraphPtr
HistVectorMap ChannelTickModProcHists
Name nameReplace(Name name, const AdcChannelData &acd, Index itkm) const
std::map< Index, HistVector > HistVectorMap
std::map< Index, IndexVector > IndexVectorMap
unsigned int Index
std::string string
Definition: nybbler.cc:12
HistVectorMap ChannelTickModFullHists
std::shared_ptr< TH1 > HistPtr
const TimeOffsetTool * m_tickOffsetTool
FloatVVectorMap MaxTickMods
Index getChannelIndex() const
std::shared_ptr< State > StatePtr
IndexVector m_PlotChannels
std::map< Index, Index > IndexMap
State & state() const
void setChannelData(const AdcChannelData &acd) const
DataMap view(const AdcChannelData &acd) const override
Index setChannel(Index igran) const
static constexpr double ps
Definition: Units.h:99
std::vector< float > FloatVector
bool updateWithView() const override
DataMap viewMap(const AdcChannelDataMap &acds) const override
int processChannelTickMod(const AdcChannelData &acd, Index itkm0, Index itkm, float &sigMean) const
int makeTickModPlots(Index &nplot) const
std::vector< FloatVector > FloatVVector
int processAccumulation(Index &nplot) const
AdcChannelDataMap acdMap
AdcTickModViewer(fhicl::ParameterSet const &ps)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
const AdcChannelStringTool * m_adcStringBuilder
IndexVectorMap phaseChannels
std::vector< Index > IndexVector
int processAccumulatedChannel(Index &nplot) const
static Index badIndex()
std::map< Index, GraphPtr > GraphMap
std::vector< HistPtr > HistVector