LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
DrawWireHist_tool.cc
Go to the documentation of this file.
1 
12 
14 
19 
20 #include "TH1F.h"
21 
22 namespace evdb_tool {
23 
24  class DrawWireHist : public IWaveformDrawer {
25  public:
26  explicit DrawWireHist(const fhicl::ParameterSet& pset);
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  void BookHistogram(raw::ChannelID_t&, float, float);
37 
38  float fMaximum;
39  float fMinimum;
40 
41  std::vector<int> fColorMap;
42  std::unordered_map<std::string, std::unique_ptr<TH1F>> fRecoHistMap;
43  };
44 
45  //----------------------------------------------------------------------
46  // Constructor.
48  {
49  configure(pset);
50  }
51 
53  {
54  fColorMap.push_back(kBlue);
55  fColorMap.push_back(kMagenta);
56  fColorMap.push_back(kBlack);
57  fColorMap.push_back(kRed);
58 
59  fRecoHistMap.clear();
60  }
61 
63  raw::ChannelID_t& channel,
64  float lowBin,
65  float numTicks)
66  {
69 
70  // Check if we're supposed to draw raw hits at all
71  if (rawOpt->fDrawRawDataOrCalibWires == 0) return;
72 
73  //grab the singleton with the event
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  int nWireLabels = 0;
84  for (size_t imod = 0; imod < recoOpt->fWireLabels.size(); ++imod) {
85  // Step one is to recover the hits for this label that match the input channel
86  art::InputTag const which = recoOpt->fWireLabels[imod];
87 
89  if (!event->getByLabel(which, wireVecHandle)) continue;
90  ++nWireLabels;
91 
92  for (size_t wireIdx = 0; wireIdx < wireVecHandle->size(); wireIdx++) {
93  art::Ptr<recob::Wire> wire(wireVecHandle, wireIdx);
94 
95  if (wire->Channel() != channel) continue;
96 
97  const std::vector<float>& signalVec = wire->Signal();
98 
99  TH1F* histPtr = fRecoHistMap.at(which.encode()).get();
100 
101  for (size_t idx = 0; idx < signalVec.size(); idx++) {
102  histPtr->Fill(float(idx) + 0.5, signalVec[idx]);
103 
104  fMinimum = std::min(fMinimum, signalVec[idx]);
105  fMaximum = std::max(fMaximum, signalVec[idx]);
106  }
107 
108  histPtr->SetLineColor(fColorMap.at((nWireLabels - 1) % recoOpt->fWireLabels.size()));
109 
110  // There is only one channel displayed so if here we are done
111  break;
112  }
113  } //end loop over HitFinding modules
114  }
115 
116  void DrawWireHist::Draw(const std::string& options, float maxLowVal, float maxHiVal)
117  {
118  for (const auto& histMap : fRecoHistMap) {
119  TH1F* histPtr = histMap.second.get();
120 
121  // Set the limits
122  histPtr->SetMaximum(maxHiVal);
123  histPtr->SetMinimum(maxLowVal);
124 
125  histPtr->Draw(options.c_str());
126  }
127  }
128 
129  //......................................................................
130  void DrawWireHist::BookHistogram(raw::ChannelID_t& channel, float startTick, float numTicks)
131  {
135  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout const>()->Get();
136 
137  // Get rid of the previous histograms
138  fRecoHistMap.clear();
139 
140  // Now add a histogram for each of the wire labels
141  for (auto& tag : recoOpt->fWireLabels) {
142  // figure out the signal type for this plane, assume that
143  // plane n in each TPC/cryostat has the same type
144  geo::SigType_t sigType = wireReadoutGeom.SignalType(channel);
145  std::string tagString(tag.encode());
146  int numBins = numTicks;
147 
148  fRecoHistMap[tagString] = std::make_unique<TH1F>(
149  "fCALTQHisto", ";t [ticks];q [ADC]", numBins, startTick, startTick + numTicks);
150 
151  TH1F* histPtr = fRecoHistMap.at(tagString).get();
152 
153  histPtr->SetMaximum(cst->fRecoQHigh[(size_t)sigType]);
154  histPtr->SetMinimum(cst->fRecoQLow[(size_t)sigType]);
155 
156  histPtr->SetLineColor(kBlue);
157  histPtr->SetLineWidth(1);
158 
159  histPtr->GetXaxis()->SetLabelSize(0.10); // was 0.15
160  histPtr->GetXaxis()->SetLabelOffset(0.01); // was 0.00
161  histPtr->GetXaxis()->SetTitleSize(0.10); // was 0.15
162  histPtr->GetXaxis()->SetTitleOffset(0.60); // was 0.80
163 
164  histPtr->GetYaxis()->SetLabelSize(0.10); // was 0.15
165  histPtr->GetYaxis()->SetLabelOffset(0.002); // was 0.00
166  histPtr->GetYaxis()->SetTitleSize(0.10); // was 0.15
167  histPtr->GetYaxis()->SetTitleOffset(0.16); // was 0.80
168  }
169  }
170 
172 }
std::unordered_map< std::string, std::unique_ptr< TH1F > > fRecoHistMap
DrawWireHist(const fhicl::ParameterSet &pset)
const art::Event * GetEvent() const
Definition: EventHolder.cxx:45
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
int fDrawRawDataOrCalibWires
0 for raw
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
void BookHistogram(raw::ChannelID_t &, float, float)
float getMaximum() const override
std::string encode() const
Definition: InputTag.cc:97
Singleton to hold the current art::Event for the event display.
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
The color scales used by the event display.
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
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:223
enum geo::_plane_sigtype SigType_t
Enumerate the possible plane projections.
static EventHolder * Instance()
Definition: EventHolder.cxx:15
std::vector< int > fColorMap
This provides an interface for tools which are tasked with drawing the "wire" data (deconvolved wavef...
std::vector< float > Signal() const
Return a zero-padded full length vector filled with RoI signal.
Definition: Wire.cxx:30
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
void Fill(evdb::View2D &, raw::ChannelID_t &, float, float) override
Definition: fwd.h:26
Event finding and building.