All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DrawRawHist_tool.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file DrawRawHist_tool.cc
3 /// \author T. Usher
4 ////////////////////////////////////////////////////////////////////////
5 
13 #include "lardataobj/RawData/raw.h"
14 
15 #include "nuevdb/EventDisplayBase/EventHolder.h"
16 
17 #include "art/Utilities/ToolMacros.h"
18 #include "art/Framework/Principal/Handle.h"
19 #include "art/Framework/Services/Registry/ServiceHandle.h"
20 #include "messagefacility/MessageLogger/MessageLogger.h"
21 
22 #include "TH1F.h"
23 
24 namespace evdb_tool {
25 
26  class DrawRawHist : public IWaveformDrawer {
27  public:
28  explicit DrawRawHist(const fhicl::ParameterSet& pset);
29 
30  ~DrawRawHist();
31 
32  void configure(const fhicl::ParameterSet& pset) override;
33  void Fill(evdb::View2D&, raw::ChannelID_t&, float, float) override;
34  void Draw(const std::string&, float, float) override;
35 
36  float
37  getMaximum() const override
38  {
39  return fMaximum;
40  };
41  float
42  getMinimum() const override
43  {
44  return fMinimum;
45  };
46 
47  private:
48  void BookHistogram(raw::ChannelID_t&, float, float);
49 
50  float fMaximum;
51  float fMinimum;
52 
53  std::unique_ptr<TH1F> fRawDigitHist;
54  };
55 
56  //----------------------------------------------------------------------
57  // Constructor.
58  DrawRawHist::DrawRawHist(const fhicl::ParameterSet& pset) { configure(pset); }
59 
61 
62  void
63  DrawRawHist::configure(const fhicl::ParameterSet& pset)
64  {
65  return;
66  }
67 
68  void
69  DrawRawHist::Fill(evdb::View2D& view2D, raw::ChannelID_t& channel, float lowBin, float numTicks)
70  {
71  art::ServiceHandle<evd::RawDrawingOptions const> rawOpt;
72 
73  //grab the singleton with the event
74  const art::Event* event = evdb::EventHolder::Instance()->GetEvent();
75  if (!event) return;
76 
77  // Handle histograms
78  BookHistogram(channel, lowBin, numTicks);
79 
80  fMinimum = std::numeric_limits<float>::max();
81  fMaximum = std::numeric_limits<float>::lowest();
82 
83  // Loop over the possible producers of RawDigits
84  for (const auto& rawDataLabel : rawOpt->fRawDataLabels) {
85  art::Handle<std::vector<raw::RawDigit>> rawDigitVecHandle;
86  event->getByLabel(rawDataLabel, rawDigitVecHandle);
87 
88  if (!rawDigitVecHandle.isValid()) continue;
89 
90  for (size_t rawDigitIdx = 0; rawDigitIdx < rawDigitVecHandle->size(); rawDigitIdx++) {
91  art::Ptr<raw::RawDigit> rawDigit(rawDigitVecHandle, rawDigitIdx);
92 
93  if (rawDigit->Channel() != channel) continue;
94 
95  // We will need the pedestal service...
96  const lariov::DetPedestalProvider& pedestalRetrievalAlg =
97  art::ServiceHandle<lariov::DetPedestalService const>()->GetPedestalProvider();
98 
99  // recover the pedestal
100  float pedestal = 0;
101 
102  if (rawOpt->fPedestalOption == 0) { pedestal = pedestalRetrievalAlg.PedMean(channel); }
103  else if (rawOpt->fPedestalOption == 1) {
104  pedestal = rawDigit->GetPedestal();
105  }
106  else if (rawOpt->fPedestalOption == 2) {
107  pedestal = 0;
108  }
109  else {
110  mf::LogWarning("DrawRawHist")
111  << " PedestalOption is not understood: " << rawOpt->fPedestalOption
112  << ". Pedestals not subtracted.";
113  }
114 
115  std::vector<short> uncompressed(rawDigit->Samples());
116  raw::Uncompress(rawDigit->ADCs(), uncompressed, rawDigit->Compression());
117 
118  TH1F* histPtr = fRawDigitHist.get();
119 
120  for (size_t idx = 0; idx < uncompressed.size(); idx++) {
121  float signalVal = float(uncompressed[idx]) - pedestal;
122 
123  histPtr->Fill(float(idx) + 0.5, signalVal);
124  }
125 
126  short minimumVal = *std::min_element(uncompressed.begin(), uncompressed.end());
127  short maximumVal = *std::max_element(uncompressed.begin(), uncompressed.end());
128 
129  fMinimum = float(minimumVal) - pedestal;
130  fMaximum = float(maximumVal) - pedestal;
131 
132  histPtr->SetLineColor(kBlack);
133 
134  // There is only one channel displayed so if here we are done
135  break;
136  }
137  }
138 
139  return;
140  }
141 
142  void
143  DrawRawHist::Draw(const std::string& options, float maxLowVal, float maxHiVal)
144  {
145  TH1F* histPtr = fRawDigitHist.get();
146 
147  // Do we have valid limits to set?
148  histPtr->SetMaximum(maxHiVal);
149  histPtr->SetMinimum(maxLowVal);
150 
151  histPtr->Draw(options.c_str());
152 
153  return;
154  }
155 
156  //......................................................................
157  void
158  DrawRawHist::BookHistogram(raw::ChannelID_t& channel, float startTick, float numTicks)
159  {
160  art::ServiceHandle<evd::ColorDrawingOptions const> cst;
161  art::ServiceHandle<geo::Geometry const> geo;
162 
163  // Get rid of the previous histograms
164  if (fRawDigitHist.get()) fRawDigitHist.reset();
165 
166  // figure out the signal type for this plane, assume that
167  // plane n in each TPC/cryostat has the same type
168  geo::SigType_t sigType = geo->SignalType(channel);
169  int numBins = numTicks;
170 
171  fRawDigitHist = std::make_unique<TH1F>(
172  "fRAWQHisto", ";t [ticks];q [ADC]", numBins, startTick, startTick + numTicks);
173 
174  TH1F* histPtr = fRawDigitHist.get();
175 
176  histPtr->SetMaximum(cst->fRawQHigh[(size_t)sigType]);
177  histPtr->SetMinimum(cst->fRawQLow[(size_t)sigType]);
178 
179  histPtr->SetLineColor(kBlack);
180  histPtr->SetLineWidth(1);
181 
182  histPtr->GetXaxis()->SetLabelSize(0.10); // was 0.15
183  histPtr->GetXaxis()->SetLabelOffset(0.01); // was 0.00
184  histPtr->GetXaxis()->SetTitleSize(0.10); // was 0.15
185  histPtr->GetXaxis()->SetTitleOffset(0.60); // was 0.80
186 
187  histPtr->GetYaxis()->SetLabelSize(0.10); // was 0.15
188  histPtr->GetYaxis()->SetLabelOffset(0.002); // was 0.00
189  histPtr->GetYaxis()->SetTitleSize(0.10); // was 0.15
190  histPtr->GetYaxis()->SetTitleOffset(0.16); // was 0.80
191  }
192 
193  DEFINE_ART_CLASS_TOOL(DrawRawHist)
194 }
void Draw(const std::string &, float, float) override
void Fill(evdb::View2D &, raw::ChannelID_t &, float, float) override
Definition of basic raw digits.
float getMinimum() const override
The color scales used by the event display.
enum geo::_plane_sigtype SigType_t
Collect all the RawData header files together.
This provides an interface for tools which are tasked with drawing the &quot;wire&quot; data (deconvolved wavef...
float getMaximum() const override
virtual float PedMean(raw::ChannelID_t ch) const =0
Retrieve pedestal information.
DrawRawHist(const fhicl::ParameterSet &pset)
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker options
void configure(const fhicl::ParameterSet &pset) override
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
std::unique_ptr< TH1F > fRawDigitHist
void BookHistogram(raw::ChannelID_t &, float, float)
art framework interface to geometry description