RawDataDrawer.h
Go to the documentation of this file.
1 /// \file RawDataDrawer.h
2 /// \brief Class to aid in the rendering of RawData objects
3 /// \author messier@indiana.edu
4 #ifndef EVD_RAWDATADRAWER_H
5 #define EVD_RAWDATADRAWER_H
6 
8 #include "larcoreobj/SimpleTypesAndConstants/geo_types.h" // geo::PlaneID
9 
10 #include <vector>
11 
12 #ifndef __CINT__
13 #include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h" // lariov::ChannelStatusProvider::Status_t
14 #endif
15 
16 class TH1F;
17 class TVirtualPad;
18 namespace detinfo {
19  class DetectorPropertiesData;
20 }
21 namespace evdb {
22  class View2D;
23 }
24 namespace raw {
25  class RawDigit;
26 }
27 namespace util {
28  class PlaneDataChangeTracker_t;
29 } // namespace util
30 
31 namespace evd {
32 
33  namespace details {
34  class RawDigitCacheDataClass;
36  typedef ::util::PlaneDataChangeTracker_t CacheID_t;
37  } // namespace details
38 
39  /// Aid in the rendering of RawData objects
40  class RawDataDrawer {
41  public:
42  RawDataDrawer();
43  ~RawDataDrawer();
44 
45  /**
46  * @brief Draws raw digit content in 2D wire plane representation
47  * @param evt source for raw digits
48  * @param view target rendered object
49  * @param plane number of the plane to be drawn
50  * @param bZoomToRoI whether to render only te region of interest
51  *
52  * This function performs pre-rendering of the raw digit content into a
53  * 2D view of the wire plane as TDC vs. wire number.
54  * The material for rendering is created and sent to view object for actual
55  * rendering.
56  * The pre-rendering result currently depends on information from the
57  * current rendering canvas, and in particular on its viewport in the
58  * (wire, TDC) space.
59  *
60  * If no zoom to the region of interest is required, the region itself is
61  * computed (only if not known yet) while the rendering is performed.
62  * If the zoom is required instead, rendering is performed in two steps;
63  * in the first, run only of no region of interest is known yet, the region
64  * is extracted. In the second, that information is used for rendering.
65  */
66  void RawDigit2D(art::Event const& evt,
67  detinfo::DetectorPropertiesData const& detProp,
68  evdb::View2D* view,
69  unsigned int plane,
70  bool bZoomToRoI = false);
71 
72  void FillQHisto(const art::Event& evt, unsigned int plane, TH1F* histo);
73 
74  void FillTQHisto(const art::Event& evt, unsigned int plane, unsigned int wire, TH1F* histo);
75 
76  double
77  StartTick() const
78  {
79  return fStartTick;
80  }
81  double
83  {
84  return fTicks;
85  }
86 
87  /// Fills the viewport information from the specified pad
88  void ExtractRange(TVirtualPad* pPad, std::vector<double> const* zoom = nullptr);
89 
90  /// Fills the viewport borders from the specified extremes
91  void SetDrawingLimits(float low_wire, float high_wire, float low_tdc, float high_tdc);
92 
93  int GetRegionOfInterest(int plane, int& minw, int& maxw, int& mint, int& maxt);
94 
95  /// Forgets about the current region of interest
96  void ResetRegionOfInterest();
97 
98  /// Returns whether there is currently a valid region of interest
99  /// for the specified plane
100  bool hasRegionOfInterest(geo::PlaneID::PlaneID_t plane) const;
101 
102  void GetChargeSum(int plane, double& charge, double& convcharge);
103 
104  private:
105  typedef struct {
106  int adc = 0; ///< total ADC count in this box
107  bool good = false; ///< whether the channel is not bad
108  } BoxInfo_t;
109 
110  typedef struct {
111  unsigned int width = 0; // width of pad in pixels
112  unsigned int height = 0; // heigt of pad in pixels
113 
114  /// Returns whether the stored value is valid
115  bool
116  isFilled() const
117  {
118  return (width != 0) && (height != 0);
119  }
120 
121  /// Returns whether the stored value is valid
122  operator bool() const { return isFilled(); }
123 
124  } PadResolution_t; ///< Stores the information about the drawing area
125 
126  /// Helper class to be used with ChannelLooper()
127  class OperationBaseClass;
128  class ManyOperations;
129  class BoxDrawer;
131 
132  // Since this is a private facility, we indulge in non-recommended practises
133  // like friendship; these classes have the ability to write their findings
134  // directly into RawDataDrawer; the alternative would be to have an
135  // interface writing that information exposed to the public, that has the
136  // draw back that we completely lose control on who can use it.
137  // Other solutions might be also possible...
138  // but this is already more complicated than needed.
139  friend class BoxDrawer;
140  friend class RoIextractorClass;
141 
142  /// Cache of raw digits
143  // Never use raw pointers. Unless you are dealing with CINT, that is.
145 
146 #ifndef __CINT__
147  /// Prepares for a new event (if somebody tells it to)
148  void Reset(art::Event const& event);
149 
150  /// Reads raw::RawDigits; also triggers Reset()
151  void GetRawDigits(art::Event const& evt);
152 
153  /// Returns whether a channel with the specified status should be processed
154  bool ProcessChannelWithStatus(lariov::ChannelStatusProvider::Status_t channel_status) const;
155 #endif // __CINT__
156 
157  double fStartTick; ///< low tick
158  double fTicks; ///< number of ticks of the clock
159 
160  std::vector<int> fWireMin; ///< lowest wire in interesting region for each plane
161  std::vector<int> fWireMax; ///< highest wire in interesting region for each plane
162  std::vector<int> fTimeMin; ///< lowest time in interesting region for each plane
163  std::vector<int> fTimeMax; ///< highest time in interesting region for each plane
164 
165  std::vector<double> fRawCharge; ///< Sum of Raw Charge
166  std::vector<double> fConvertedCharge; ///< Sum of Charge Converted using Birks' formula
167 
168  PadResolution_t PadResolution; ///< stored pad resolution
169 
170  details::CacheID_t* fCacheID; ///< information about the last processed plane
171 
172  // TODO with ROOT 6, turn this into a std::unique_ptr()
173  details::CellGridClass* fDrawingRange; ///< information about the viewport
174 
175  /// Performs the 2D wire plane drawing
176  void DrawRawDigit2D(art::Event const& evt, evdb::View2D* view, unsigned int plane);
177 
178  /**
179  * @brief Makes sure raw::RawDigit's are available for the current settings
180  * @param evt event to read the digits from
181  * @param ts a cache ID assessing the new state the cache should move to
182  *
183  * The function will ask the data cache for an update
184  * (RawDigitCacheDataClass::Update()).
185  * The cache will evaluate whether it is already in a state compatible with
186  * ts or if cache needs to be invalidated, in which case it will fill with
187  * new data.
188  * This method also triggers a Reset() if the target state differs from the
189  * old one.
190  */
191  void GetRawDigits(art::Event const& evt, details::CacheID_t const& new_timestamp);
192 
193  // Helper functions for drawing
194  bool RunOperation(art::Event const& evt, OperationBaseClass* operation);
195  void QueueDrawingBoxes(evdb::View2D* view,
196  geo::PlaneID const& pid,
197  std::vector<BoxInfo_t> const& BoxInfo);
198  void RunDrawOperation(art::Event const& evt,
199  detinfo::DetectorPropertiesData const& detProp,
200  evdb::View2D* view,
201  unsigned int plane);
202  void RunRoIextractor(art::Event const& evt, unsigned int plane);
203  void SetDrawingLimitsFromRoI(geo::PlaneID::PlaneID_t plane);
204  void
206  {
207  SetDrawingLimitsFromRoI(pid.Plane);
208  }
209 
210  /// Empty collection, used in return value of invalid digits
211  static std::vector<raw::RawDigit> const EmptyRawDigits;
212 
213  }; // class RawDataDrawer
214 
215 }
216 
217 #endif
218 ////////////////////////////////////////////////////////////////////////
Namespace for general, non-LArSoft-specific utilities.
double fStartTick
low tick
unsigned int PlaneID_t
Type for the ID number.
Definition: geo_types.h:473
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
details::CacheID_t * fCacheID
information about the last processed plane
bool isFilled() const
Returns whether the stored value is valid.
int16_t adc
Definition: CRTFragment.hh:202
Raw data description.
std::vector< double > fRawCharge
Sum of Raw Charge.
std::vector< int > fWireMin
lowest wire in interesting region for each plane
std::vector< int > fTimeMax
highest time in interesting region for each plane
unsigned short Status_t
type representing channel status
double fTicks
number of ticks of the clock
LArSoft includes.
Definition: InfoTransfer.h:33
PadResolution_t PadResolution
stored pad resolution
Cached set of RawDigitInfo_t.
std::vector< int > fWireMax
highest wire in interesting region for each plane
void SetDrawingLimitsFromRoI(geo::PlaneID const pid)
double TotalClockTicks() const
Definition: RawDataDrawer.h:82
General LArSoft Utilities.
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
Definition of data types for geometry description.
Detects the presence of a new event, data product or wire plane.
double StartTick() const
Definition: RawDataDrawer.h:77
Aid in the rendering of RawData objects.
Definition: RawDataDrawer.h:40
Interface for experiment-specific channel quality info provider.
static std::vector< raw::RawDigit > const EmptyRawDigits
Empty collection, used in return value of invalid digits.
details::CellGridClass * fDrawingRange
information about the viewport
std::vector< int > fTimeMin
lowest time in interesting region for each plane
::util::PlaneDataChangeTracker_t CacheID_t
Definition: RawDataDrawer.h:35
Manages a grid-like division of 2D space.
TCEvent evt
Definition: DataStructs.cxx:7
evd::details::RawDigitCacheDataClass * digit_cache
Cache of raw digits.
int bool
Definition: qglobal.h:345
Event finding and building.
std::vector< double > fConvertedCharge
Sum of Charge Converted using Birks&#39; formula.