JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwCorrelatorNew.h
Go to the documentation of this file.
1#pragma once
2
3// Parent Class
4#include "VQwDataHandler.h"
5
6// System headers
7#include <fstream>
8#include <utility>
9// Forward declarations
10class TH1D;
11class TH2D;
12class QwRootFile;
13
14// ROOT headers
15#include <TVectorD.h>
16#include <TMatrixD.h>
17/**
18 * \class QwCorrelatorNew
19 * \ingroup QwAnalysis
20 * \brief Data handler computing correlations and linear-regression coefficients
21 *
22 * Uses Bevington/Pebay algorithms to estimate correlations between independent
23 * and dependent variables selected from subsystem arrays. Produces summary
24 * histograms and optional output trees/files for further analysis.
25 */
26class QwCorrelatorNew : public VQwDataHandler, public MQwDataHandlerCloneable<QwCorrelatorNew>
27{
28 public:
29 /// \brief Constructor with name
30 QwCorrelatorNew(const TString& name);
32 ~QwCorrelatorNew() override;
33
34 private:
35 static bool fPrintCorrelations;
36 public:
37 static void DefineOptions(QwOptions &options);
38 void ProcessOptions(QwOptions &options);
39
40 void ParseConfigFile(QwParameterFile& file) override;
41
42 Int_t LoadChannelMap(const std::string& mapfile) override;
43
44 /// \brief Connect to Channels (asymmetry/difference only)
45 /// \param asym Subsystem array with asymmetries
46 /// \param diff Subsystem array with differences
47 /// \return 0 on success, non-zero on failure
49
50 void ProcessData() override;
51 void FinishDataHandler() override{
53 }
54 void CalcCorrelations();
55
56 /// \brief Construct the tree branches
58 QwRootFile *treerootfile,
59 const std::string& treeprefix = "",
60 const std::string& branchprefix = "") override;
61 /// \brief Fill the tree branches
62 void FillTreeBranches(QwRootFile *treerootfile) override { };
63
64 /// \brief Construct the histograms in a folder with a prefix
65 void ConstructHistograms(TDirectory *folder, TString &prefix) override;
66 /// \brief Fill the histograms
67 void FillHistograms() override;
68
69 void ClearEventData() override;
70 void AccumulateRunningSum(VQwDataHandler &value, Int_t count = 0, Int_t ErrorMask = 0xFFFFFFF) override;
71
72 protected:
73
74 Int_t fBlock;
75
77
78 std::vector< std::string > fIndependentFull;
79
80 // Using the fDependentType and fDependentName from base class, but override the IV arrays
81 std::vector< EQwHandleType > fIndependentType;
82 std::vector< std::string > fIndependentName;
83
84 std::vector< const VQwHardwareChannel* > fIndependentVar;
85 std::vector< Double_t > fIndependentValues;
86
89 std::string fAlphaOutputPath;
91 void OpenAlphaFile(const std::string& prefix);
92 void WriteAlphaFile();
93 void CloseAlphaFile();
94
95 TTree* fTree;
96
99 std::string fAliasOutputPath;
100 std::ofstream fAliasOutputFile;
101 void OpenAliasFile(const std::string& prefix);
102 void WriteAliasFile();
103 void CloseAliasFile();
104
107
109 std::vector<int> fErrCounts_IV;
110 std::vector<int> fErrCounts_DV;
111
112 unsigned int fGoodEvent;
113
114 private:
115
117 int nP, nY;
118
119 // monitoring histos for iv & dv
120 std::vector<TH1D> fHnames;
121 std::vector<TH1D> fH1iv;
122 std::vector<TH1D> fH1dv;
123 std::vector<std::vector<TH2D>> fH2iv;
124 std::vector<std::vector<TH2D>> fH2dv;
125
127
128 // Default Constructor
130
131
132 private:
133 Int_t fErrorFlag; ///< is information valid
134 Long64_t fGoodEventNumber; ///< accumulated so far
135
136 /// correlations
137 TMatrixD mRPY, mRYP;
138 TMatrixD mRPP, mRYY;
139 TMatrixD mRYYp;
140
141 /// unnormalized covariances
142 TMatrixD mVPY, mVYP;
143 TMatrixD mVPP, mVYY;
144 TMatrixD mVYYp;
145 /// variances
146 TVectorD mVP, mVY;
147 TVectorD mVYp;
148
149 /// normalized covariances
150 TMatrixD mSPY, mSYP;
151 TMatrixD mSPP, mSYY;
152 TMatrixD mSYYp;
153 /// sigmas
154 TVectorD mSP, mSY;
155 TVectorD mSYp;
156
157 /// mean values
158 TVectorD mMP, mMY, mMYp;
159
160
161 /// slopes
162 TMatrixD Axy, Ayx, dAxy, dAyx; // found slopes and their standard errors
163
164 public:
165
166 void solve();
167 bool failed() { return fGoodEventNumber < nP + 1; }
168
169 // after last event
170 void printSummaryP() const;
171 void printSummaryY() const;
172 void printSummaryYP() const;
173 void printSummaryAlphas() const;
174 void printSummaryMeansWithUnc() const;
176
177 void print();
178 void init();
179 void clear();
180 void setDims(int a, int b){ nP = a; nY = b;}
181
182 /// Get mean value of a variable, returns error code
183 Int_t getMeanP(const int i, Double_t &mean) const;
184 Int_t getMeanY(const int i, Double_t &mean) const;
185 Int_t getMeanYprime(const int i, Double_t &mean) const;
186
187 /// Get mean value of a variable, returns error code
188 Int_t getSigmaP(const int i, Double_t &sigma) const;
189 Int_t getSigmaY(const int i, Double_t &sigma) const;
190 Int_t getSigmaYprime(const int i, Double_t &sigma) const;
191
192 /// Get mean value of a variable, returns error code
193 Int_t getCovarianceP (int i, int j, Double_t &covar) const;
194 Int_t getCovariancePY(int ip, int iy, Double_t &covar) const;
195 Int_t getCovarianceY (int i, int j, Double_t &covar) const;
196
197 double getUsedEve() const { return fGoodEventNumber; };
198
199 // Addition-assignment
200 QwCorrelatorNew& operator+=(const std::pair<TVectorD,TVectorD>& rhs);
202 // Addition using addition-assignment
203
204
205 friend QwCorrelatorNew operator+(QwCorrelatorNew lhs, // passing lhs by value helps optimize chained a+b+c
206 const QwCorrelatorNew& rhs) // otherwise, both parameters may be const references
207 {
208 lhs += rhs; // reuse compound assignment
209 return lhs; // return the result by value (uses move constructor)
210 }
211
212 /// \brief Output stream operator
213 friend std::ostream& operator<< (std::ostream& stream, const QwCorrelatorNew& h);
214};
215
216/// Output stream operator
217inline std::ostream& operator<< (std::ostream& stream, const QwCorrelatorNew& h)
218{
219 stream << "LRB: " << h.fGoodEventNumber << " events";
220 return stream;
221}
222
223
224// Register this handler with the factory
226
227
#define REGISTER_DATA_HANDLER_FACTORY(A)
Definition QwFactory.h:263
std::ostream & operator<<(std::ostream &stream, const QwCorrelatorNew &h)
Output stream operator.
Virtual base class for data handlers accessing multiple subsystems.
Command-line and configuration file options processor.
Definition QwOptions.h:141
Configuration file parser with flexible tokenization and search capabilities.
A wrapper class for a ROOT file or memory mapped file.
Definition QwRootFile.h:849
Data handler computing correlations and linear-regression coefficients.
void printSummaryAlphas() const
Int_t fErrorFlag
is information valid
std::vector< TH1D > fH1iv
Int_t getMeanYprime(const int i, Double_t &mean) const
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Construct the histograms in a folder with a prefix.
Int_t getSigmaP(const int i, Double_t &sigma) const
Get mean value of a variable, returns error code.
Long64_t fGoodEventNumber
accumulated so far
QwCorrelatorNew & operator+=(const std::pair< TVectorD, TVectorD > &rhs)
std::vector< Double_t > fIndependentValues
void ParseConfigFile(QwParameterFile &file) override
void ProcessData() override
Int_t getSigmaY(const int i, Double_t &sigma) const
TMatrixD Axy
slopes
Int_t getSigmaYprime(const int i, Double_t &sigma) const
std::vector< TH1D > fHnames
static void DefineOptions(QwOptions &options)
friend std::ostream & operator<<(std::ostream &stream, const QwCorrelatorNew &h)
Output stream operator.
void ConstructTreeBranches(QwRootFile *treerootfile, const std::string &treeprefix="", const std::string &branchprefix="") override
Construct the tree branches.
void printSummaryMeansWithUncCorrected() const
std::ofstream fAliasOutputFile
void OpenAliasFile(const std::string &prefix)
TVectorD mMP
mean values
void FillHistograms() override
Fill the histograms.
double getUsedEve() const
std::vector< TH1D > fH1dv
std::vector< std::vector< TH2D > > fH2iv
void ClearEventData() override
Int_t getMeanP(const int i, Double_t &mean) const
Get mean value of a variable, returns error code.
std::string fAlphaOutputFileBase
Int_t ConnectChannels(QwSubsystemArrayParity &asym, QwSubsystemArrayParity &diff) override
Connect to Channels (asymmetry/difference only)
~QwCorrelatorNew() override
std::vector< int > fErrCounts_DV
Int_t getMeanY(const int i, Double_t &mean) const
TMatrixD mRPY
correlations
void printSummaryP() const
std::string fAliasOutputPath
std::vector< std::string > fIndependentFull
void printSummaryY() const
TMatrixD mSPY
normalized covariances
std::string fAlphaOutputPath
QwCorrelatorNew(const TString &name)
Constructor with name.
friend QwCorrelatorNew operator+(QwCorrelatorNew lhs, const QwCorrelatorNew &rhs)
std::string fAlphaOutputFileSuff
TVectorD mSP
sigmas
void FinishDataHandler() override
std::vector< int > fErrCounts_IV
std::vector< EQwHandleType > fIndependentType
TMatrixD mVPY
unnormalized covariances
std::vector< const VQwHardwareChannel * > fIndependentVar
std::vector< std::vector< TH2D > > fH2dv
void printSummaryYP() const
TVectorD mVP
variances
void FillTreeBranches(QwRootFile *treerootfile) override
Fill the tree branches.
void ProcessOptions(QwOptions &options)
std::string fAliasOutputFileSuff
static bool fPrintCorrelations
unsigned int fGoodEvent
Int_t getCovariancePY(int ip, int iy, Double_t &covar) const
std::string fAliasOutputFileBase
void printSummaryMeansWithUnc() const
std::vector< std::string > fIndependentName
Int_t getCovarianceY(int i, int j, Double_t &covar) const
void OpenAlphaFile(const std::string &prefix)
Int_t getCovarianceP(int i, int j, Double_t &covar) const
Get mean value of a variable, returns error code.
void setDims(int a, int b)
Subsystem array container specialized for parity analysis with asymmetry calculations.
Abstract base for handlers that consume multiple subsystems and produce derived outputs.
void AccumulateRunningSum()
VQwDataHandler(const TString &name)