20 #include "TDirectory.h" 28 using Tick = AdcSignalVector::size_type;
36 : m_LogLevel(ps.
get<
int>(
"LogLevel")),
37 m_DataType(ps.
get<
int>(
"DataType")),
40 m_TickRebin(ps.
get<
Index>(
"TickRebin")),
42 m_ClockFactor(ps.
get<
float>(
"ClockFactor")),
43 m_ClockOffset(ps.
get<
float>(
"ClockOffset")),
48 m_EmptyColor(ps.
get<double>(
"EmptyColor")),
49 m_ChannelLineModulus(ps.
get<
Index>(
"ChannelLineModulus")),
51 m_Palette(ps.
get<
int>(
"Palette")),
55 m_PlotSizeX(ps.
get<
Index>(
"PlotSizeX")),
56 m_PlotSizeY(ps.
get<
Index>(
"PlotSizeY")),
57 m_PlotFileName(ps.
get<
string>(
"PlotFileName")),
58 m_RootFileName(ps.
get<
string>(
"RootFileName")),
60 m_pOnlineChannelMapTool(nullptr),
62 const string myname =
"AdcDataPlotter::ctor: ";
71 string stringBuilder =
"adcStringBuilder";
74 cout << myname <<
"WARNING: AdcChannelStringTool not found: " << stringBuilder <<
endl;
83 const string tnam =
"tickRanges";
85 if ( ptool ==
nullptr ) {
86 cout << myname <<
"WARNING: Tick range tool not found: " << tnam <<
endl;
93 cout << myname <<
"WARNING: Tick range not found: " <<
m_TickRange <<
endl;
101 string::size_type ipos = crn.find(
":");
102 if ( crn.size() == 0 || crn ==
"data" ) {
103 m_crs.emplace_back(
"data", 0, 0,
"All data");
104 }
else if ( ipos != string::npos ) {
105 cout << myname <<
"Decoding explicit range " << crn <<
endl;
106 Index ich1 = std::stoi(crn.substr(0,ipos));
107 Index ich2 = std::stoi(crn.substr(ipos+1));
108 Name rename = crn.substr(0,ipos) +
"to" + crn.substr(ipos+1);
109 m_crs.emplace_back(rename, ich1, ich2, crn);
111 if ( pcrt ==
nullptr ) {
113 if ( pcrt ==
nullptr ) {
114 cout << myname <<
"ERROR: IndexRangeTool not found: channelRanges" <<
endl;
117 if ( pcrt !=
nullptr ) {
120 m_crs.push_back(ran);
122 cout << myname <<
"WARNING: Channel range not found: " << crn <<
endl;
129 string stnam =
"runDataTool";
132 cout << myname <<
"ERROR: RunDataTool " << stnam
133 <<
" not found. Metric limits will not be evaluated." <<
endl;
135 cout << myname <<
"RunDataTool retrieved." <<
endl;
140 cout << myname <<
"Configuration: " <<
endl;
144 cout << myname <<
" TickRange: " << descTickRange <<
endl;
146 cout << myname <<
" ChannelRanges: [";
149 if ( ! first ) cout <<
", ";
154 cout << myname <<
" FembTickOffsets: [";
157 if ( first ) first =
false;
164 if ( m_FembTickOffsets.size() ) {
171 cout << myname <<
" SkipChannelStatus: [";
174 if ( ! first ) cout <<
", ";
181 cout << myname <<
" ChannelLinePattern: {";
184 if ( ! first ) cout <<
", ";
203 const string myname =
"AdcDataPlotter::viewMap: ";
205 if ( acds.size() == 0 ) {
206 cout << myname <<
"WARNING: Channel map is empty. No plot is created." <<
endl;
217 for (
const AdcChannelDataMap::value_type& iacd : acds ) {
219 cout << myname <<
"WARNING: Channel map has invalid channels. No plot is created." <<
endl;
221 Tick ntick = isRaw ? iacd.second.raw.size() : iacd.second.samples.size();
222 if ( ntick > maxtick ) maxtick = ntick;
226 unsigned long tick1 = 0;
227 unsigned long tick2 = maxtick;
232 Tick ntick = tick2 - tick1;
233 ret.
setInt(
"ntick", ntick);
235 cout << myname <<
"ERROR: Invalid tick range." <<
endl;
243 cout << myname <<
"WARNING: RunData not found for run " << run <<
"." <<
endl;
254 if ( ran.name ==
"data" ) {
255 ran.begin = acdChanFirst;
256 ran.end = acdChanLast + 1;
258 if ( ! ran.isValid() ) {
259 cout << myname <<
"ERROR: Skipping invalid channel range " << ran.name <<
endl;
262 Index chanBegin = ran.first();
263 Index chanEnd = ran.end;
267 Index chanDataEnd = ichanDataEnd == acds.end() ? chanEnd : ichanDataEnd->first;
268 Index chanDataBegin = ichanDataBegin == acds.end() ? chanDataEnd : ichanDataBegin->first;
270 if ( chanDataEnd <= chanDataBegin ) {
271 if (
m_LogLevel >= 2 ) cout << myname <<
"Data has no entries in channel range " << ran.name <<
endl;
273 cout << myname <<
" chanBegin: " << chanBegin <<
endl;
274 cout << myname <<
" chanEnd: " << chanEnd <<
endl;
275 cout << myname <<
" chanDataBegin: " << chanDataBegin <<
endl;
276 cout << myname <<
" chanDataEnd: " << chanDataEnd <<
endl;
280 if (
m_LogLevel >= 2 ) cout << myname <<
"Creating histogram for channel range " << ran.name <<
endl;
281 AdcIndex nchan = chanEnd - chanBegin;
284 dm.
setInt(
"chan1", acdChanFirst);
285 dm.
setInt(
"chan2", acdChanLast-1);
291 string szunits =
"(ADC counts)";
294 if ( szunits.find(
" ") != string::npos ) szunits =
"(" + szunits +
")";
296 string zunit = szunits;
297 if ( zunit.find(
" ") != string::npos ) zunit =
"(" + zunit +
")";
298 bool zhasTick = zunit.find(
"Tick") != string::npos || zunit.find(
"tick") != string::npos;
299 if ( ! zhasTick ) zunit +=
"/tick";
301 htitl +=
"; Tick; Channel; Signal [" + zunit +
"]";
308 TH2* ph =
new TH2F(hname.c_str(), htitl.c_str(), ntick, tick1, tick2, nchan, chanBegin, chanEnd);
309 ph->SetDirectory(
nullptr);
311 if (
m_LogLevel >= 2 ) cout << myname <<
"Created histogram " << hname <<
endl;
312 ph->GetZaxis()->SetRangeUser(zmin, zmax);
314 double zempty = colorEmptyBins ? zmin - 1000.0 : 0.0;
316 for (
Index icha=1; icha<=nchan; ++icha ) {
317 Index ibin0 = (ntick+2)*icha + 1;
318 for (
Index ibin=ibin0; ibin<ibin0+ntick; ++ibin ) ph->SetBinContent(ibin, zempty);
321 for (
AdcChannel chan=chanDataBegin; chan<chanDataEnd; ++chan ) {
323 if ( iacd == acds.end() )
continue;
327 if ( drops.size() && std::find(drops.begin(), drops.end(), chstat) != drops.end() )
continue;
328 Index ibiny = chan-chanBegin + 1;
331 cout << myname <<
"WARNING: Unable to find data view name " <<
m_DataView <<
endl;
333 for (
Index ient=0; ient<nent; ++ient ) {
335 cout << myname <<
"Processing data view " << ient <<
"/" << nent <<
endl;
338 if ( pacd ==
nullptr ) {
339 cout << myname <<
"ERROR: Skipping null view entry " <<
m_DataView <<
"[" << ient
343 if ( pacd->
channel() != chan ) {
344 cout << myname <<
"ERROR: Skipping view entry " <<
m_DataView <<
"[" << ient
345 <<
"] with the wrong the wrong channel: " 346 << pacd->
channel() <<
" != " << chan <<
"." <<
endl;
353 bool isRawPed =
false;
358 Tick nsam = isRaw ? raw.size() : sams.size();
368 cout << myname <<
" FEMB tick offsets provided without online channel mapping tool." <<
endl;
372 Index ifmb = chanOn/128;
377 cout << myname <<
"Filling channel-tick histogram with " << nsam <<
" samples and offset " 378 << dsam <<
" for channel " << chan <<
endl;
380 Index ibin = ph->GetBin(1, ibiny);
381 for (
Tick itck=tick1; itck<tick2; ++itck, ++ibin ) {
387 if ( (isSig || isNsg) && isam >= pacd->
signal.size() ) {
389 cout << myname <<
" Signal array not filled for sample " << isam
390 <<
" and above--stopping fill." <<
endl;
395 if ( isam < sams.size() ) sig = sams[isam];
397 }
else if ( isRawPed ) {
398 if ( isam < raw.size() ) sig = raw[isam] - ped;
400 }
else if ( isRaw && isam >= raw.size() ) {
403 }
else if ( isSig ) {
404 if ( isam < sams.size() && isam < keep.size() ) {
405 if ( keep[isam] ) sig = sams[isam];
409 }
else if ( isNsg ) {
410 if ( isam < sams.size() ) {
411 if ( isam >= keep.size() || !keep[isam] ) sig = sams[isam];
416 cout << myname <<
"Fill failed for bin " << ibin <<
endl;
418 if ( colorEmptyBins && sig < zmin ) sig = zmin;
419 ph->SetBinContent(ibin, sig);
428 ph->SetDirectory(
nullptr);
431 ph->GetZaxis()->SetRangeUser(-zmax, zmax);
439 if ( ppal ==
nullptr ) {
440 cout << myname <<
"ERROR: Unable to find palette " <<
m_Palette <<
endl;
460 if ( icha > chanBegin && icha < chanEnd ) {
465 TLatex* pptl =
nullptr;
466 if ( ptitl.size() ) {
467 pptl =
new TLatex(0.01, 0.015, ptitl.c_str());
469 pptl->SetTextFont(42);
470 pptl->SetTextSize(0.030);
479 std::getline(cin, line);
482 cout << myname <<
"Created plot ";
483 cout <<
"for channels [" << chanBegin <<
" - " 484 << chanEnd <<
"): " << ofname <<
endl;
486 if ( ofrname.size() ) {
487 TFile* pfile = TFile::Open(ofrname.c_str(),
"UPDATE");
489 if (
m_LogLevel > 1 ) cout << myname <<
"Wrote " << ph->GetName() <<
" to " << ofrname <<
endl;
497 ret.
setInt(
"nhist", nhist);
511 if ( pnbl ==
nullptr )
return name;
515 return pnbl->
build(acd, dm, name);
std::vector< AdcCount > AdcCountVector
IndexVector m_SkipChannelStatus
int add(unsigned int ipad, TObject *pobj, std::string sopt="", bool replace=false)
DataMap & setStatus(int stat)
IndexVector m_ChannelLinePattern
int replace(std::string substr, const T &xsub)
int setRangeZ(double y1, double y2)
int setCanvasSize(int wx, int wy)
IntVector m_FembTickOffsets
Name m_OnlineChannelMapTool
int setFrameFillColor(int col)
Name nameReplace(Name name, const AdcChannelData &acd, const IndexRange &ran) const
std::vector< Index > IndexVector
int addHorizontalLine(double yoff=0.0, double lenfrac=1.0, int isty=1)
AdcDataPlotter(fhicl::ParameterSet const &ps)
T get(std::string const &key) const
int addAxis(bool flag=true)
void setInt(Name name, int val)
const AdcChannelStringTool * m_adcStringBuilder
DataMap viewMap(const AdcChannelDataMap &acds) const override
static constexpr double ps
Name label(Index ilab=0) const
Index channelStatus() const
std::vector< bool > AdcFilterVector
std::vector< int > IntVector
const std::vector< int > & colorVector() const
NameVector m_ChannelRanges
std::optional< T > get_if_present(std::string const &key) const
void line(double t, double *p, double &x, double &y, double &z)
const AdcChannelData * viewEntry(Name vpnam, AdcIndex ient) const
AdcLongIndex channelClock
std::vector< AdcSignal > AdcSignalVector
const RunDataTool * m_prdtool
std::string rangeString() const
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
static Index badChannel()
const IndexMapTool * m_pOnlineChannelMapTool
std::vector< Name > NameVector
auto const & get(AssnsNode< L, R, D > const &r)
SetStat setFormulaPars(TFormula *form)
int addHorizontalModLines(double ymod, double yoff=0.0, double lenfrac=1.0, int isty=3)
void setPalette(int ipal)
int print(std::string fname, std::string spat="{,}")
AdcLongIndex triggerClock() const
QTextStream & endl(QTextStream &s)
static const RootPalette * find(unsigned int ipal)
Index m_ChannelLineModulus