RawDataDrawer.cxx
Go to the documentation of this file.
1 /**
2 * @file RawDataDrawer.cxx
3 * @brief Class to aid in the rendering of RawData objects
4 * @author trj@fnal.gov
5 *
6 * This class prepares the rendering of the raw digits content for the 3D view
7 * of the display.
8 */
9 #include <cmath> // std::abs(), ...
10 #include <utility> // std::pair<>, std::move()
11 #include <memory> // std::unique_ptr()
12 #include <tuple>
13 #include <limits> // std::numeric_limits<>
14 #include <type_traits> // std::add_const_t<>, ...
15 #include <typeinfo> // to use typeid()
16 #include <algorithm> // std::fill(), std::find_if(), ...
17 #include <cstddef> // std::ptrdiff_t
18 
19 #include "TH1F.h"
20 #include "TMarker3DBox.h"
21 #include "TFrame.h"
22 #include "TVirtualPad.h"
23 
26 #include "nuevdb/EventDisplayBase/View3D.h"
27 #include "nuevdb/EventDisplayBase/EventHolder.h"
31 #include "RawDataProducts/raw.h"
32 #include "Geometry/GeometryGAr.h"
37 
45 #include "cetlib_except/demangle.h"
46 
47 #include "TPolyLine.h"
48 #include "TPolyLine3D.h"
49 #include "TLine.h"
50 #include "TBox.h"
51 #include "TText.h"
52 #include "TMath.h"
53 
54 namespace {
55  // Utility function to make uniform error messages.
56  void writeErrMsg(const char* fcn,
57  cet::exception const& e)
58  {
59  mf::LogWarning("RecoBaseDrawer") << "RecoBaseDrawer::" << fcn
60  << " failed with message:\n"
61  << e;
62  }
63  }
64 
65 
66  namespace gar {
67  namespace evd {
68 
69  //......................................................................
71  {
72  fEventTQHist = (TH1F*) new TH1F("eventTQHist","ADC Sum vs Time, All Channels;time (ticks);ADC Sum",100,0,10000);
73  fDigitTQHist = (TH1F*) new TH1F("digitTQHist","ADC Sum vs Time, One Channel;time (ticks);ADC Sum",100,0,10000);
74  }
75 
76  //......................................................................
78  {
79  }
80 
81  //......................................................................
83  TH1F* histo)
84  {
85 
86  gar::raw::ADCvector_t uncompressed;
87  uncompressed.resize(dig.Samples());
88  short ped = dig.Pedestal();
89  gar::raw::Uncompress(dig.ADCs(),uncompressed,ped,dig.Compression());
90  for(size_t t = 0; t < uncompressed.size(); ++t)
91  histo->Fill(t, 1. * uncompressed[t] - 1. * dig.Pedestal());
92 
93  return;
94  }//end loop over raw hits
95 
96  // to do -- need to get xyz position of a channel from the channel map -- it's not just a rectangular grid of pixels
97 
98  //......................................................................
100  evdb::View3D* view)
101  {
102  // Check if we're supposed to draw raw hits at all
106  auto fTime = gar::providerFrom<detinfo::DetectorClocksServiceGAr>();
107  auto detProp = gar::providerFrom<detinfo::DetectorPropertiesService>();
108 
109  double driftVelocity = detProp->DriftVelocity(detProp->Efield(),
110  detProp->Temperature());
111 
112  if(rawopt->fDrawRawOrReco > 0) return;
113 
114  std::vector<const raw::RawDigit*> rawhits;
115  this->GetRawDigits(evt, rawhits);
116 
117  fEventTQHist->Reset();
118  fDigitTQHist->Reset();
119 
120  //auto const& colorSet = cdopt->RawQ();
121 
122  gar::raw::ADCvector_t uncompressed;
123  for(auto dig : rawhits){
124 
125  this->FillQHisto(*dig, fEventTQHist);
126  if(dig->Channel() == rawopt->fChannel)
127  this->FillQHisto(*dig, fDigitTQHist);
128 
129  // draw the digit as time, y, z with the latter coordinates
130  // given by the channel map.
131  float xyz[3];
132 
133  geom->ChannelToPosition((unsigned int)dig->Channel(),
134  xyz);
135 
136  //std::cout << "RDGeo: " << dig->Channel() << " " << xyz[0] << " " << xyz[1] << " " << xyz[2] << std::endl;
137  double chanposx = xyz[0];
138 
139  // draw hit channels on the readout planes in gray. No timing or x information.
140  //int c = kGray;
141  //int s=1;
142  //int w=1;
143  //TPolyLine3D& rdpos = view->AddPolyLine3D(2,c,w,s);
144  //rdpos.SetPoint(0,xyz[2],xyz[0],xyz[1]);
145  //rdpos.SetPoint(1,xyz[2]+1,xyz[0],xyz[1]);
146  //// std::cout << "adding a raw digit: " << xyz[0] << " " << xyz[1] << " " << xyz[2] << std::endl;
147 
148  // loop over the ADC values for this digit and draw the value if it
149  // is above the threshold
150  //TMarker3DBox *box = nullptr;
151 
152  uncompressed.resize(dig->Samples());
153  short ped = dig->Pedestal();
154  gar::raw::Uncompress(dig->ADCs(),uncompressed,ped,dig->Compression());
155 
156  for(size_t t = 0; t < dig->Samples(); ++t){
157  if(uncompressed[t] < rawopt->fMinSignal) continue;
158 
159  double driftdistance = fTime->TPCTick2Time(t) * driftVelocity;
160 
161  if (chanposx < 0)
162  {
163  xyz[0] = chanposx + driftdistance;
164  }
165  else
166  {
167  xyz[0] = chanposx - driftdistance;
168  }
169 
170  // nb. coordinates are so Y is up, but ROOT thinks Z is up, so report (z,x,y)
171  // somehow these boxes don't work -- draw short lines instead
172  //box = &(view->AddMarker3DBox(xyz[2],
173  // xyz[0],
174  // xyz[1],
175  // 0.5, // the extent is 1/2 tick
176  // 0.5 * 0.3, // to fix geom->ChannelPitch(),
177  // 0.5 * 0.3 // to fix geom->ChannelPitch()
178  // ));
179  //box->SetFillStyle(1001);
180  ////auto tmpcolor = colorSet.GetColor(uncompressed[t]);
181  //box->SetFillColor(kGreen);
182  //box->SetBit(kCannotPick);
183 
184  //std::cout << "adding a raw digit: " << xyz[0] << " " << xyz[1] << " " << xyz[2] << std::endl;
185 
186  // try drawing with polylines, little green segments
187 
188 
189  int c2 = kGreen;
190  int s2=1;
191  int w2=1;
192 
193  // nb. coordinates are so Y is up, but ROOT thinks Z is up, so report (z,x,y)
194 
195  TPolyLine3D& rdpos = view->AddPolyLine3D(2,c2,w2,s2);
196  rdpos.SetPoint(0,xyz[2],xyz[0]-0.3,xyz[1]);
197  rdpos.SetPoint(1,xyz[2],xyz[0]+0.3,xyz[1]);
198 
199  } // end loop over ADC values for the digit
200  }//end loop over raw digits
201 
202  return;
203  }
204 
205  //......................................................................
207  std::vector<const raw::RawDigit*> & digits)
208  {
209  digits.clear();
210 
212 
213  std::vector<const raw::RawDigit*> temp;
214 
215  try{
216  evt.getView(rawopt->fRawDataLabel, temp);
217  for(size_t t = 0; t < temp.size(); ++t){
218  digits.push_back(temp[t]);
219  }
220  }
221  catch(cet::exception& e){
222  writeErrMsg("GetDigits", e);
223  }
224 
225  return;
226  } // RawDataDrawer::GetRawDigits()
227 
228  } // namespace evd
229  }
230 
231  ////////////////////////////////////////////////////////////////////////
std::vector< ADC_t > ADCvector_t
Definition: RawTypes.h:13
void RawDigit3D(art::Event const &evt, evdb::View3D *view)
Draws raw digit content in 2D wire plane representation.
void GetRawDigits(art::Event const &evt, std::vector< const raw::RawDigit * > &digits)
Makes sure raw::RawDigit&#39;s are available for the current settings.
gar::raw::Compress_t Compression() const
Compression algorithm selector.
Definition: RawDigit.h:195
TH1F * fDigitTQHist
Charge vs time for a single channel in an event.
Definition: RawDataDrawer.h:67
const double e
LArSoft includes.
Definition: InfoTransfer.h:33
TH1F * fEventTQHist
Charge vs time for all digits in an event.
Definition: RawDataDrawer.h:66
double fMinSignal
minimum ADC count to display a time bin
float Pedestal() const
Definition: RawDigit.h:192
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
Definition: RawDigit.h:189
General GArSoft Utilities.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
Definition: DataViewImpl.h:500
void Uncompress(const gar::raw::ADCvector_t &adc, gar::raw::ADCvector_t &uncompressed, gar::raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:183
void FillQHisto(gar::raw::RawDigit const &dig, TH1F *histo)
TCEvent evt
Definition: DataStructs.cxx:7
art framework interface to geometry description
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:191
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:67
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33