18 #include "TDirectory.h" 26 using std::ostringstream;
28 using Tick = AdcSignalVector::size_type;
44 state.
ppad.reset(
nullptr);
54 : m_LogLevel(ps.
get<
int>(
"LogLevel")),
55 m_WireAngle(ps.
get<
float>(
"WireAngle")),
56 m_DataType(ps.
get<
int>(
"DataType")),
58 m_DriftSpeed(ps.
get<
float>(
"DriftSpeed")),
63 m_SignalThreshold(ps.
get<
float>(
"SignalThreshold")),
64 m_SkipBadChannels(ps.
get<
bool>(
"SkipBadChannels")),
65 m_ShowAllTicks(ps.
get<
bool>(
"ShowAllTicks")),
66 m_FirstTick(ps.
get<unsigned long>(
"FirstTick")),
67 m_LastTick(ps.
get<unsigned long>(
"LastTick")),
68 m_ShowWires(ps.
get<
bool>(
"ShowWires")),
69 m_ShowCathode(ps.
get<
bool>(
"ShowCathode")),
71 m_ShowGrid(ps.
get<
bool>(
"ShowGrid")),
75 m_pChannelStatusProvider(nullptr),
77 const string myname =
"AdcDetectorPlotter::ctor: ";
79 string stringBuilder =
"adcStringBuilder";
82 cout << myname <<
"WARNING: AdcChannelStringTool not found: " << stringBuilder <<
endl;
85 if (
m_LogLevel >= 1 ) cout << myname <<
"Fetching channel status service." <<
endl;
88 cout << myname <<
"WARNING: Channel status provider not found." <<
endl;
92 cout << myname <<
"Configuration: " <<
endl;
98 cout << myname <<
" XMin: " <<
m_XMin <<
" cm" <<
endl;
99 cout << myname <<
" XMax: " <<
m_XMax <<
" cm" <<
endl;
100 cout << myname <<
" ZMin: " <<
m_ZMin <<
" cm" <<
endl;
101 cout << myname <<
" ZMax: " <<
m_ZMax <<
" cm" <<
endl;
103 cout << myname <<
" SkipBadChannels: " << (
m_SkipBadChannels ?
"true" :
"false") << endl;
109 cout << myname <<
" ShowTpcSets: [";
112 if ( first ) first =
false;
130 string gname = pgeo ==
nullptr ?
"NONE" : pgeo->
DetectorName();
132 cout << myname <<
"Derived: " <<
endl;
133 cout << myname <<
" Geometry name: " << gname <<
endl;
134 cout << myname <<
" # selected planes: " << sel.
planeIDs().size() <<
endl;
135 cout << myname <<
" # selected wires: " << wdat.size() <<
endl;
136 cout << myname <<
" # selected wire points: " << wsum.
size() <<
endl;
137 cout << myname <<
" # selected channels: " << wmap.size() <<
endl;
149 const string myname =
"AdcDetectorPlotter::view: ";
154 if ( acds.size() == 0 ) {
155 cout << myname <<
"WARNING: Channel map is empty. No data extracted." <<
endl;
160 string hname =
"hdet";
165 string sttlx =
"Drift coordinate [cm]";
173 string sttly =
"Wire coordinate [cm]";
175 if ( acdFirst.
run() != state.
run ||
178 cout << myname <<
"ERROR: Received unexpected event ID. Clearing data." <<
endl;
179 cout << myname <<
"State: " << state.
event <<
"-" << state.
subrun <<
"-" << state.
event <<
endl;
180 cout << myname <<
" Data: " << acdFirst.
event() <<
"-" << acdFirst.
subRun() <<
"-" << acdFirst.
event() <<
endl;
185 if (
m_LogLevel >= 2 ) cout << myname <<
" Starting new event." <<
endl;
186 initializeState(state, acdFirst);
192 TGraph* pg =
new TGraph;
193 pg->SetTitle(sttl.c_str());
194 pg->GetXaxis()->SetTitle(sttlx.c_str());
195 pg->GetYaxis()->SetTitle(sttly.c_str());
196 state.
ppad->add(pg,
"P");
197 state.
ppad->graph()->Expand(512);
198 state.
ppad->setRangeX(xmin, xmax);
204 TGraph* pgw =
new TGraph;
205 pgw->SetMarkerColor(cols.
red());
206 pgw->Expand(wins.size());
207 for (
Index iwin=0; iwin<wins.size(); ++iwin ) {
209 pgw->SetPoint(iwin, xsign*win.
x, win.
z);
211 state.
ppad->add(pgw,
"P");
214 TGraph* pgc =
new TGraph;
215 pgc->SetMarkerColor(cols.
green());
216 pgc->Expand(wins.size());
217 for (
Index iwin=0; iwin<wins.size(); ++iwin ) {
219 pgc->SetPoint(iwin, xsign*(win.
x + win.
driftMax), win.
z);
221 state.
ppad->add(pgc,
"P");
224 if ( spttl.size() ) {
225 state.
pttl.reset(
new TLatex(0.01, 0.015, spttl.c_str()));
226 state.
pttl->SetNDC();
227 state.
pttl->SetTextFont(42);
228 state.
pttl->SetTextSize(0.030);
233 TGraph* pgr = state.
ppad->graph();
234 if ( pgr ==
nullptr ) {
235 cout <<
"ERROR: Graph not found." <<
endl;
239 cout << myname <<
" Adding to existing event. Graph point count is " << pgr->GetN() <<
endl;
244 for (
const AdcChannelDataMap::value_type& iacd : acds ) {
246 cout << myname <<
"WARNING: Channel map has invalid channels. No plot is created." <<
endl;
248 Tick ntick = iacd.second.samples.size();
249 if ( ntick > maxtick ) maxtick = ntick;
253 AdcIndex nchan = chanLast + 1 - chanFirst;
254 if (
m_LogLevel >= 2 ) cout << myname <<
" Input channel count is " << nchan <<
endl;
256 for (
const AdcChannelDataMap::value_type& iacd : acds ) {
257 if (
m_LogLevel >= 3 ) cout << myname <<
" Filling with channel " << iacd.first <<
endl;
267 if ( state.
ppad->graph()->GetN() == 0 ) {
268 cout << myname <<
"Graph has no points. Adding one to avoid root exception." <<
endl;
271 if (
m_LogLevel >= 2 ) cout << myname <<
" Graph point count: " << state.
ppad->graph()->GetN() <<
endl;
278 const string myname =
"AdcDetectorPlotter::endEvent: ";
282 cout << myname <<
"WARNING: No data recorded." <<
endl;
285 if ( evi.
run != state.
run ) {
286 cout << myname <<
"ERROR: Received request for unexpected run: " << evi.
run <<
endl;
290 cout << myname <<
"ERROR: Received request for unexpected event: " << evi.
event <<
endl;
301 const string myname =
"AdcDetectorPlotter::addChannel: ";
304 if ( !isRaw && !isPrep ) {
305 cout << myname <<
"ERROR: Invalid data type: " <<
m_DataType <<
endl;
309 TGraph* pg = state.
ppad->graph();
310 if ( pg ==
nullptr ) {
311 cout << myname <<
"ERROR: Graph is missing." <<
endl;
318 cout << myname <<
" Adding " << nsam << (isRaw ?
" raw" :
" processed")
319 <<
" sample" << (nsam==1 ?
"" :
"s") <<
endl;
321 for (
auto ient=
rng.first; ient!=
rng.second; ++ient) {
333 for (
Index isam=isam1; isam<isam2; ++isam ) {
336 float x = win.
x + driftVelocity*(isam -
m_Tick0);
338 if ( x < x1 )
continue;
339 if ( x > x2 )
continue;
341 Index ipt = pg->GetN();
342 pg->SetPoint(ipt, xsign*x, z);
346 sout << myname <<
"Added point " << ipt <<
" (" << x <<
", " << z <<
")";
347 cout << sout.str() <<
endl;
350 cout << myname <<
"Skipped sample " << isam <<
" with signal " << sig <<
endl;
virtual bool IsBad(raw::ChannelID_t channel) const =0
Returns whether the specified channel is bad in the current run.
const WireInfoMap & dataMap() const
const lariov::ChannelStatusProvider * m_pChannelStatusProvider
DataMap & setStatus(int stat)
const PlaneIDVector & planeIDs() const
DataMap viewMap(const AdcChannelDataMap &acds) const override
const GeometryCore * geometry() const
IndexVector m_ShowTpcSets
art framework interface to geometry description
StatePtr getState() const
DataMap endEvent(const DuneEventInfo &) const override
int addChannel(const AdcChannelData &acd, double xfac) const
void selectWireAngle(double wireAngle, double tol=0.001)
void selectTpcSets(const IndexVector &itpss)
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
const AdcChannelStringTool * m_adcStringBuilder
std::vector< WireInfo > WireInfoVector
AdcDetectorPlotter(fhicl::ParameterSet const &ps)
static constexpr double ps
Description of geometry of one entire detector.
const WireSummary & fillWireSummary()
std::vector< Index > IndexVector
const WireInfoVector & fillData()
std::multimap< Index, const WireInfo * > WireInfoMap
Interface for experiment-specific channel quality info provider.
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
static Index badChannel()
auto const & get(AssnsNode< L, R, D > const &r)
Interface for experiment-specific service for channel quality info.
const WireInfoMap & fillDataMap()
QTextStream & endl(QTextStream &s)