JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
GrandCorrelator.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 GrandCorrelator
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 GrandCorrelator : public VQwDataHandler, public MQwDataHandlerCloneable<GrandCorrelator>
27{
28 public:
29 /// \brief Constructor with name
30 GrandCorrelator(const TString& name);
32 ~GrandCorrelator() 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 std::vector<int> fErrCounts_ALL;
112
113 unsigned int fGoodEvent;
114
115 private:
116
118 int nP, nY;
119
120 // monitoring histos for iv & dv
121 std::vector<TH1D> fHnames;
122 std::vector<TH1D> fH1iv;
123 std::vector<TH1D> fH1dv;
124 std::vector<std::vector<TH2D>> fH2iv;
125 std::vector<std::vector<TH2D>> fH2dv;
126
128
129 // Default Constructor
131
132
133 private:
134 Int_t fErrorFlag; ///< is information valid
135 Long64_t fGoodEventNumber; ///< accumulated so far
136
137 /// correlations
138 TMatrixD mRPY, mRYP;
139 TMatrixD mRPP, mRYY;
140 TMatrixD mRYYp;
141
142 /// unnormalized covariances
143 TMatrixD mVPY, mVYP;
144 TMatrixD mVPP, mVYY;
145 TMatrixD mVYYp;
146 /// variances
147 TVectorD mVP, mVY;
148 TVectorD mVYp;
149
150 /// normalized covariances
151 TMatrixD mSPY, mSYP;
152 TMatrixD mSPP, mSYY;
153 TMatrixD mSYYp;
154 /// sigmas
155 TVectorD mSP, mSY;
156 TVectorD mSYp;
157
158 /// mean values
159 TVectorD mMP, mMY, mMYp;
160
161//========================================================
162 /// new matrices and vectors
163 TMatrixD mNij, mSij, mMij;
164 TMatrixD mCij, mVij, mRij;
165 TMatrixD mVFULL, mRFULL, mSFULL;
167 TMatrixD mVFULL_clean;
168 TMatrixD mSFULL_clean;
169 std::vector<const VQwHardwareChannel*> fAllVar; // stores the channels (pointers)
170 std::vector<double> fAllValues; // stores the current event values
171 std::vector<bool> fAllGood;
172 std::vector<std::string> fAllName;
173//========================================================
174
175
176 /// slopes
177 TMatrixD Axy, Ayx, dAxy, dAyx; // found slopes and their standard errors
178
179 public:
180
181 void solve();
182 bool failed() { return fGoodEventNumber < nP + 1; }
183
184 // after last event
185 void printSummaryP() const;
186 void printSummaryY() const;
187 void printSummaryYP() const;
188 void printSummaryAlphas() const;
189 void printSummaryMeansWithUnc() const;
191
192 void print();
193 void init();
194 void clear();
195 void setDims(int a, int b){ nP = a; nY = b;}
196
197 /// Get mean value of a variable, returns error code
198 Int_t getMeanP(const int i, Double_t &mean) const;
199 Int_t getMeanY(const int i, Double_t &mean) const;
200 Int_t getMeanYprime(const int i, Double_t &mean) const;
201
202 /// Get mean value of a variable, returns error code
203 Int_t getSigmaP(const int i, Double_t &sigma) const;
204 Int_t getSigmaY(const int i, Double_t &sigma) const;
205 Int_t getSigmaYprime(const int i, Double_t &sigma) const;
206
207 /// Get mean value of a variable, returns error code
208 Int_t getCovarianceP (int i, int j, Double_t &covar) const;
209 Int_t getCovariancePY(int ip, int iy, Double_t &covar) const;
210 Int_t getCovarianceY (int i, int j, Double_t &covar) const;
211
212 double getUsedEve() const { return fGoodEventNumber; };
213
214 // Addition-assignment
215 GrandCorrelator& operator+=(const std::pair<TVectorD,TVectorD>& rhs);
217 // Addition using addition-assignment
218
219
220 friend GrandCorrelator operator+(GrandCorrelator lhs, // passing lhs by value helps optimize chained a+b+c
221 const GrandCorrelator& rhs) // otherwise, both parameters may be const references
222 {
223 lhs += rhs; // reuse compound assignment
224 return lhs; // return the result by value (uses move constructor)
225 }
226
227 /// \brief Output stream operator
228 friend std::ostream& operator<< (std::ostream& stream, const GrandCorrelator& h);
229};
230
231/// Output stream operator
232inline std::ostream& operator<< (std::ostream& stream, const GrandCorrelator& h)
233{
234 stream << "LRB: " << h.fGoodEventNumber << " events";
235 return stream;
236}
237
238
239// Register this handler with the factory
#define REGISTER_DATA_HANDLER_FACTORY(A)
Definition QwFactory.h:263
std::ostream & operator<<(std::ostream &stream, const GrandCorrelator &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.
std::ofstream fAliasOutputFile
std::string fAliasOutputFileSuff
TVectorD mMP
mean values
TMatrixD Axy
slopes
void printSummaryAlphas() const
void printSummaryMeansWithUncCorrected() const
std::vector< int > fErrCounts_ALL
Int_t getSigmaP(const int i, Double_t &sigma) const
Get mean value of a variable, returns error code.
friend std::ostream & operator<<(std::ostream &stream, const GrandCorrelator &h)
Output stream operator.
Int_t fErrorFlag
is information valid
TMatrixD mVPY
unnormalized covariances
TVectorD mVP
variances
std::vector< const VQwHardwareChannel * > fAllVar
TMatrixD mSPY
normalized covariances
GrandCorrelator & operator+=(const std::pair< TVectorD, TVectorD > &rhs)
std::vector< std::string > fAllName
std::string fAliasOutputFileBase
Int_t getMeanY(const int i, Double_t &mean) const
void ClearEventData() override
std::vector< double > fAllValues
void printSummaryMeansWithUnc() const
TVectorD mSP
sigmas
Int_t getMeanYprime(const int i, Double_t &mean) const
std::string fAlphaOutputFileSuff
void ProcessOptions(QwOptions &options)
void printSummaryY() const
void printSummaryP() const
void OpenAlphaFile(const std::string &prefix)
std::vector< int > fErrCounts_DV
void FillHistograms() override
Fill the histograms.
GrandCorrelator(const TString &name)
Constructor with name.
static void DefineOptions(QwOptions &options)
std::vector< TH1D > fH1iv
std::string fAlphaOutputPath
void ProcessData() override
std::vector< TH1D > fHnames
void OpenAliasFile(const std::string &prefix)
void printSummaryYP() const
Int_t getSigmaYprime(const int i, Double_t &sigma) const
Long64_t fGoodEventNumber
accumulated so far
std::vector< std::string > fIndependentFull
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Construct the histograms in a folder with a prefix.
Int_t getCovarianceY(int i, int j, Double_t &covar) const
void FinishDataHandler() override
Int_t ConnectChannels(QwSubsystemArrayParity &asym, QwSubsystemArrayParity &diff) override
Connect to Channels (asymmetry/difference only)
std::vector< std::vector< TH2D > > fH2dv
std::string fAliasOutputPath
unsigned int fGoodEvent
TMatrixD mNij
new matrices and vectors
std::vector< EQwHandleType > fIndependentType
Int_t getCovariancePY(int ip, int iy, Double_t &covar) const
void ConstructTreeBranches(QwRootFile *treerootfile, const std::string &treeprefix="", const std::string &branchprefix="") override
Construct the tree branches.
std::vector< std::vector< TH2D > > fH2iv
std::vector< std::string > fIndependentName
~GrandCorrelator() override
Int_t getMeanP(const int i, Double_t &mean) const
Get mean value of a variable, returns error code.
std::vector< Double_t > fIndependentValues
std::vector< int > fErrCounts_IV
std::vector< const VQwHardwareChannel * > fIndependentVar
void ParseConfigFile(QwParameterFile &file) override
double getUsedEve() const
void setDims(int a, int b)
Int_t getSigmaY(const int i, Double_t &sigma) const
std::vector< bool > fAllGood
std::string fAlphaOutputFileBase
static bool fPrintCorrelations
Int_t getCovarianceP(int i, int j, Double_t &covar) const
Get mean value of a variable, returns error code.
void FillTreeBranches(QwRootFile *treerootfile) override
Fill the tree branches.
std::vector< TH1D > fH1dv
TMatrixD mRPY
correlations
friend GrandCorrelator operator+(GrandCorrelator lhs, const GrandCorrelator &rhs)
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)