JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwTrendHandler.h
Go to the documentation of this file.
1/*!
2 * \file QwTrendHandler.h
3 * \brief Data handler that books time-ordered TProfile "strip charts"
4 * \author GitHub Copilot
5 * \date 2026-05-14
6 */
7
8#pragma once
9
10// Parent Class
11#include "VQwDataHandler.h"
12
13// Forward declarations
14class TH1;
15class TProfile;
16
17/**
18 * \class QwTrendHandler
19 * \ingroup QwAnalysis
20 * \brief Data handler that replaces time-ordered strip-chart trees with TProfiles
21 *
22 * Traditional monitoring plots draw a channel value versus event (or pattern)
23 * number by streaming every event into a TTree and later projecting
24 * `value:CodaEventNumber`. That keeps a full, unbinned copy of the data on
25 * disk purely so a strip chart can be drawn.
26 *
27 * QwTrendHandler instead pre-books one TProfile per configured channel with the
28 * time-ordering index (a monotonically increasing counter that mirrors the
29 * event/pattern number) on the x-axis and the channel value on the y-axis.
30 * Each bin then stores the mean and RMS of the channel over that slice of the
31 * run, which is exactly what a strip chart conveys, at a tiny fraction of the
32 * storage cost and with no TTree required.
33 *
34 * The x-axis auto-extends (TH1::kXaxis) so runs of arbitrary length are
35 * handled without knowing the event count in advance. Because the profiles
36 * are ordinary ROOT histograms written into the histogram file, Panguin renders
37 * them with the existing `-type prof` option with no plotting-side changes.
38 */
40 public MQwDataHandlerCloneable<QwTrendHandler>
41{
42 public:
43 /// \brief Constructor with name
44 QwTrendHandler(const TString& name);
45 /// \brief Copy constructor
46 QwTrendHandler(const QwTrendHandler& source);
47 /// Virtual destructor
48 ~QwTrendHandler() override;
49
50 /// \brief Load the list of channels to trend (and binning) from the map file
51 Int_t LoadChannelMap(const std::string& mapfile) override;
52
53 /// \brief Connect to channels from the per-MPS (event) subsystem array
54 /// \param event Subsystem array providing per-MPS yields/mps channels
55 /// \return 0 on success
56 Int_t ConnectChannels(QwSubsystemArrayParity& event) override;
57
58 // The asym/diff connection uses the VQwDataHandler base implementation,
59 // which populates fDependentVar for kHandleTypeAsym/kHandleTypeDiff tokens.
60
61 /// \brief Read the current value of each connected channel
62 void ProcessData() override;
63
64 /// \brief Book one TProfile strip chart per connected channel
65 void ConstructHistograms(TDirectory* folder, TString& prefix) override;
66 /// \brief Fill each strip chart at the current time-ordering index
67 void FillHistograms() override;
68
69 protected:
70 /// Default constructor (protected for factory/child access)
72
73 /// Number of x bins for the strip-chart profiles (bounded storage)
74 Int_t fNbins;
75 /// Initial event/pattern indices per bin; the axis auto-extends (doubling the
76 /// bin width) once the run grows past fNbins*fBinWidth events
77 Double_t fBinWidth;
78 /// Skip filling when (errorflag & mask) != 0 (0 disables the check)
80 /// Time-ordering index incremented once per filled event/pattern
81 Long64_t fCounter;
82
83 /// True when booked into a fixed-size live TMapFile (ConstructHistograms was
84 /// called with folder == NULL). In that mode the strip chart is a rolling
85 /// window drawn with a plain TH1D value trace (SetBinContent): the time index
86 /// wraps back to the left edge and each new event overwrites its bin.
87 /// TProfile's several internal arrays (fArray/fSumw2/fBinEntries/fBinSumw2)
88 /// are not marshalled robustly by TMapFile::Update() and crash the live
89 /// monitor, so TProfiles are used only for the (auto-extending) file output.
90 Bool_t fRolling;
91
92 /// One strip chart per connected channel (owned by the ROOT output
93 /// directory). Held as the TH1 base so file mode can use a TProfile
94 /// (mean +/- RMS) while live TMapFile mode uses a robust TH1D value trace.
95 std::vector<TH1*> fTrend;
96};
97
98// Register this handler with the factory
#define REGISTER_DATA_HANDLER_FACTORY(A)
Definition QwFactory.h:263
Virtual base class for data handlers accessing multiple subsystems.
Subsystem array container specialized for parity analysis with asymmetry calculations.
Data handler that replaces time-ordered strip-chart trees with TProfiles.
Long64_t fCounter
Time-ordering index incremented once per filled event/pattern.
std::vector< TH1 * > fTrend
~QwTrendHandler() override
Virtual destructor.
void ProcessData() override
Read the current value of each connected channel.
Int_t ConnectChannels(QwSubsystemArrayParity &event) override
Connect to channels from the per-MPS (event) subsystem array.
Int_t fNbins
Number of x bins for the strip-chart profiles (bounded storage)
void FillHistograms() override
Fill each strip chart at the current time-ordering index.
QwTrendHandler(const TString &name)
Constructor with name.
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Book one TProfile strip chart per connected channel.
UInt_t fErrorFlagMask
Skip filling when (errorflag & mask) != 0 (0 disables the check)
QwTrendHandler()
Default constructor (protected for factory/child access)
VQwDataHandler(const TString &name)