DrawWireHist_tool.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file DrawWireHist_tool.cc
3 /// \author T. Usher
4 ////////////////////////////////////////////////////////////////////////
5 
12 #include "nuevdb/EventDisplayBase/EventHolder.h"
13 
15 
16 #include "TH1F.h"
17 
18 namespace evdb_tool
19 {
20 
22 {
23 public:
24  explicit DrawWireHist(const fhicl::ParameterSet& pset);
25 
26  ~DrawWireHist();
27 
28  void configure(const fhicl::ParameterSet& pset) override;
29  void Fill(evdb::View2D&, raw::ChannelID_t&, float, float) override;
30  void Draw(const std::string&, float, float) override;
31 
32  float getMaximum() const override {return fMaximum;};
33  float getMinimum() const override {return fMinimum;};
34 
35 private:
36 
37  void BookHistogram(raw::ChannelID_t&, float, float);
38 
39  float fMaximum;
40  float fMinimum;
41 
42  std::vector<int> fColorMap;
43  std::unordered_map<std::string,std::unique_ptr<TH1F>> fRecoHistMap;
44 };
45 
46 //----------------------------------------------------------------------
47 // Constructor.
49 {
50  configure(pset);
51 }
52 
54 {
55 }
56 
58 {
59  fColorMap.push_back(kBlue);
60  fColorMap.push_back(kMagenta);
61  fColorMap.push_back(kBlack);
62  fColorMap.push_back(kRed);
63 
64  fRecoHistMap.clear();
65 
66  return;
67 }
68 
69 
70 void DrawWireHist::Fill(evdb::View2D& view2D,
72  float lowBin,
73  float numTicks)
74 {
77 
78  // Check if we're supposed to draw raw hits at all
79  if(rawOpt->fDrawRawDataOrCalibWires == 0) return;
80 
81  //grab the singleton with the event
82  const art::Event* event = evdb::EventHolder::Instance()->GetEvent();
83  if(!event) return;
84 
85  // Handle histograms
86  BookHistogram(channel, lowBin, numTicks);
87 
89  fMaximum = std::numeric_limits<float>::lowest();
90 
91  int nWireLabels = 0;
92  for (size_t imod = 0; imod < recoOpt->fWireLabels.size(); ++imod)
93  {
94  // Step one is to recover the hits for this label that match the input channel
95  art::InputTag const which = recoOpt->fWireLabels[imod];
96 
98  if (!event->getByLabel(which, wireVecHandle)) continue;
99  ++nWireLabels;
100 
101  for(size_t wireIdx = 0; wireIdx < wireVecHandle->size(); wireIdx++)
102  {
103  art::Ptr<recob::Wire> wire(wireVecHandle, wireIdx);
104 
105  if (wire->Channel() != channel) continue;
106 
107  const std::vector<float>& signalVec = wire->Signal();
108 
109  TH1F* histPtr = fRecoHistMap.at(which.encode()).get();
110 
111  for(size_t idx = 0; idx < signalVec.size(); idx++)
112  {
113  histPtr->Fill(float(idx)+0.5,signalVec[idx]);
114 
115  fMinimum = std::min(fMinimum,signalVec[idx]);
116  fMaximum = std::max(fMaximum,signalVec[idx]);
117  }
118 
119  histPtr->SetLineColor(fColorMap.at((nWireLabels-1) % recoOpt->fWireLabels.size()));
120 
121  // There is only one channel displayed so if here we are done
122  break;
123  }
124  }//end loop over HitFinding modules
125 
126  return;
127 }
128 
129 void DrawWireHist::Draw(const std::string& options, float maxLowVal, float maxHiVal)
130 {
131  for(const auto& histMap : fRecoHistMap)
132  {
133  TH1F* histPtr = histMap.second.get();
134 
135  // Set the limits
136  histPtr->SetMaximum(maxHiVal);
137  histPtr->SetMinimum(maxLowVal);
138 
139  histPtr->Draw(options.c_str());
140  }
141 
142  return;
143 }
144 
145 //......................................................................
146 void DrawWireHist::BookHistogram(raw::ChannelID_t& channel, float startTick, float numTicks)
147 {
152 
153  // Get rid of the previous histograms
154  fRecoHistMap.clear();
155 
156  // Now add a histogram for each of the wire labels
157  for(auto& tag : recoOpt->fWireLabels)
158  {
159  // figure out the signal type for this plane, assume that
160  // plane n in each TPC/cryostat has the same type
161  geo::SigType_t sigType = geo->SignalType(channel);
162  std::string tagString(tag.encode());
163  int numBins = numTicks;
164 
165  fRecoHistMap[tagString] = std::make_unique<TH1F>("fCALTQHisto", ";t [ticks];q [ADC]",numBins,startTick,startTick+numTicks);
166 
167  TH1F* histPtr = fRecoHistMap.at(tagString).get();
168 
169  histPtr->SetMaximum(cst->fRecoQHigh[(size_t)sigType]);
170  histPtr->SetMinimum(cst->fRecoQLow[(size_t)sigType]);
171 
172  histPtr->SetLineColor(kBlue);
173  histPtr->SetLineWidth(1);
174 
175  histPtr->GetXaxis()->SetLabelSize (0.10); // was 0.15
176  histPtr->GetXaxis()->SetLabelOffset(0.01); // was 0.00
177  histPtr->GetXaxis()->SetTitleSize (0.10); // was 0.15
178  histPtr->GetXaxis()->SetTitleOffset(0.60); // was 0.80
179 
180  histPtr->GetYaxis()->SetLabelSize (0.10 ); // was 0.15
181  histPtr->GetYaxis()->SetLabelOffset(0.002); // was 0.00
182  histPtr->GetYaxis()->SetTitleSize (0.10 ); // was 0.15
183  histPtr->GetYaxis()->SetTitleOffset(0.16 ); // was 0.80
184  }
185 }
186 
188 }
DrawWireHist(const fhicl::ParameterSet &pset)
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::string string
Definition: nybbler.cc:12
int fDrawRawDataOrCalibWires
0 for raw
void BookHistogram(raw::ChannelID_t &, float, float)
uint8_t channel
Definition: CRTFragment.hh:201
float getMaximum() const override
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
std::string encode() const
Definition: InputTag.cc:97
art framework interface to geometry description
std::vector< double > fRecoQHigh
high edge of ADC values for drawing raw digits
std::vector< double > fRecoQLow
low edge of ADC values for drawing raw digits
void Draw(const std::string &, float, float) override
void configure(const fhicl::ParameterSet &pset) override
std::vector< art::InputTag > fWireLabels
module labels that produced wires
std::unordered_map< std::string, std::unique_ptr< TH1F > > fRecoHistMap
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:231
enum geo::_plane_sigtype SigType_t
std::vector< int > fColorMap
This provides an interface for tools which are tasked with drawing the "wire" data (deconvolved wavef...
static int max(int a, int b)
std::vector< float > Signal() const
Return a zero-padded full length vector filled with RoI signal.
Definition: Wire.cxx:47
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
Declaration of basic channel signal object.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
float getMinimum() const override
LArSoft geometry interface.
Definition: ChannelGeo.h:16
void Fill(evdb::View2D &, raw::ChannelID_t &, float, float) override
Event finding and building.