66 "print correlations after determining them");
85 QwWarning <<
"GrandCorrelator: expect 0 <= block <= 3 but block = "
110 for(
size_t i = 0; i <
fAllVar.size(); ++i){
123 for(
size_t i = 0; i<
fAllVar.size(); ++i){
124 for(
size_t j = i; j<
fAllVar.size(); ++j){
129 double delta_i = xi -
mMij(i,j);
130 double delta_j = xj -
mMij(j,i);
134 mSij(i,j) += delta_i * (xi-
mMij(i,j));
138 mCij(i,j) += ((
mNij(i,j) - 1) /
mNij(i,j)) * (delta_i) * (delta_j);
144 mSij(j,i) += delta_j * (xj -
mMij(j,i));
175 QwWarning <<
"GrandCorrelator::AccumulateRunningSum "
176 <<
"can only accept other GrandCorrelator objects."
184 if (
nP == 0 ||
nY == 0) {
198 <<
"< 1% good events, "
205 QwVerbose <<
" Entries failed due to error flag: "
258 std::pair<EQwHandleType,std::string> type_name;
272 if (primary_token ==
"iv") {
277 else if (primary_token ==
"dv") {
282 else if (primary_token ==
"treetype") {
286 QwError <<
"LoadChannelMap in GrandCorrelator read invalid primary_token " << primary_token <<
QwLog::endl;
319 QwWarning <<
"GrandCorrelator::ConnectChannels(QwSubsystemArrayParity& asym, QwSubsystemArrayParity& diff): "
321 <<
", for asym/diff correlator does not have proper type, type=="
330 QwWarning <<
"QwCombiner::ConnectChannels(QwSubsystemArrayParity& asym, QwSubsystemArrayParity& diff): Dependent variable, "
332 <<
", was not found (fullname=="
360 QwWarning <<
"Independent variable for correlator has unknown type."
402 const std::string& treeprefix,
403 const std::string& branchprefix)
406 if (
nP == 0 ||
nY == 0) {
421 const std::string name = treeprefix +
fTreeName;
425 if (
fTree == NULL)
return;
432 fTree->Branch(TString(branchprefix +
"ErrorFlag"), &(this->
fErrorFlag));
434 auto bn = [&](
const TString& n) {
435 return TString(branchprefix + n);
437 auto pm = [](TMatrixD& m) {
438 return m.GetMatrixArray();
440 auto lm = [](TMatrixD& m,
const TString& n) {
441 return Form(
"%s[%d][%d]/D", n.Data(), m.GetNrows(), m.GetNcols());
443 auto branchm = [&](TTree* tree, TMatrixD& m,
const TString& n) {
444 tree->Branch(bn(n),pm(m),lm(m,n));
446 auto pv = [](TVectorD& v) {
447 return v.GetMatrixArray();
449 auto lv = [](TVectorD& v,
const TString& n) {
450 return Form(
"%s[%d]/D", n.Data(), v.GetNrows());
452 auto branchv = [&](TTree* tree, TVectorD& v,
const TString& n) {
453 tree->Branch(bn(n),pv(v),lv(v,n));
494 if (
nP == 0 ||
nY == 0) {
500 name.ReplaceAll(
" ",
"_");
501 folder->mkdir(name)->cd();
505 for (
int i = 0; i <
nP; i++) {
510 fH1iv[i].GetXaxis()->SetNdivisions(4);
516 for (
int i = 0; i <
nP; i++) {
518 for (
int j = i+1; j <
nP; j++) {
521 Form(
"iv correlation P%d_P%d, pass=%s ;P%d=%s (ppm);P%d=%s (ppm) ",
525 fH2iv[i][j].GetXaxis()->SetTitleColor(kBlue);
526 fH2iv[i][j].GetYaxis()->SetTitleColor(kBlue);
527 fH2iv[i][j].GetXaxis()->SetNdivisions(4);
528 fH2iv[i][j].GetYaxis()->SetNdivisions(4);
534 for (
int i = 0; i <
nY; i++) {
539 fH1dv[i].GetXaxis()->SetNdivisions(4);
545 for (
int i = 0; i <
nP; i++) {
547 for (
int j = 0; j <
nY; j++) {
550 Form(
"iv-dv correlation P%d_Y%d, pass=%s ;P%d=%s (ppm);Y%d=%s (ppm) ",
554 fH2dv[i][j].GetXaxis()->SetTitleColor(kBlue);
555 fH2dv[i][j].GetYaxis()->SetTitleColor(kBlue);
556 fH2dv[i][j].GetXaxis()->SetNdivisions(4);
557 fH2dv[i][j].GetYaxis()->SetNdivisions(4);
563 fHnames[0] = TH1D(
"NamesIV",Form(
"IV name list nIV=%d",
nP),
nP,0,1);
564 for (
int i = 0; i <
nP; i++)
566 fHnames[1] = TH1D(
"NamesDV",Form(
"DV name list nIV=%d",
nY),
nY,0,1);
567 for (
int i = 0; i <
nY; i++)
578 if (
nP == 0 ||
nY == 0) {
604 this->
Axy.Write(
"slopes");
605 this->
dAxy.Write(
"sigSlopes");
607 this->
mRPP.Write(
"IV_IV_correlation");
608 this->
mRPY.Write(
"IV_DV_correlation");
609 this->
mRYY.Write(
"DV_DV_correlation");
610 this->
mRYYp.Write(
"DV_DV_correlation_prime");
612 this->
mMP.Write(
"IV_mean");
613 this->
mMY.Write(
"DV_mean");
614 this->
mMYp.Write(
"DV_mean_prime");
619 Mstat.Write(
"MyStat");
622 TH1D hiv(
"IVname",
"names of IVs",
nP,-0.5,
nP-0.5);
627 TH1D hdv(
"DVname",
"names of IVs",
nY,-0.5,
nY-0.5);
632 this->
mSP.Write(
"IV_sigma");
633 this->
mSY.Write(
"DV_sigma");
634 this->
mSYp.Write(
"DV_sigma_prime");
637 this->
mVPP.Write(
"IV_IV_rawVariance");
638 this->
mVPY.Write(
"IV_DV_rawVariance");
639 this->
mVYY.Write(
"DV_DV_rawVariance");
640 this->
mVYYp.Write(
"DV_DV_rawVariance_prime");
641 TVectorD mVY2(TMatrixDDiag(this->
mVYY));
642 mVY2.Write(
"DV_rawVariance");
643 TVectorD mVP2(TMatrixDDiag(this->
mVPP));
644 mVP2.Write(
"IV_rawVariance");
645 TVectorD mVY2prime(TMatrixDDiag(this->
mVYYp));
646 mVY2prime.Write(
"DV_rawVariance_prime");
649 this->
mSPP.Write(
"IV_IV_normVariance");
650 this->
mSPY.Write(
"IV_DV_normVariance");
651 this->
mSYY.Write(
"DV_DV_normVariance");
652 this->
mSYYp.Write(
"DV_DV_normVariance_prime");
653 TVectorD sigY2(TMatrixDDiag(this->
mSYY));
654 sigY2.Write(
"DV_normVariance");
655 TVectorD sigX2(TMatrixDDiag(this->
mSPP));
656 sigX2.Write(
"IV_normVariance");
657 TVectorD sigY2prime(TMatrixDDiag(this->
mSYYp));
658 sigY2prime.Write(
"DV_normVariance_prime");
660 this->
Axy.Write(
"A_xy");
661 this->
Ayx.Write(
"A_yx");
669 std::string file = path + name;
670 fAlphaOutputFile =
new TFile(TString(file),
"RECREATE",
"correlation coefficients");
683 std::replace(label.begin(), label.end(),
'.',
'_');
687 std::string file = path + name +
".C";
690 fAliasOutputFile << Form(
"void %s(int i = 0) {", name.c_str()) << std::endl;
725 fAliasOutputFile << Form(
" TTree* tree = (TTree*) gDirectory->Get(\"mul\");") << std::endl;
726 for (
int i = 0; i <
nY; i++) {
729 for (
int j = 0; j <
nP; j++) {
906 const TVectorD& P = rhs.first;
907 const TVectorD& Y = rhs.second;
921 TVectorD delta_y(Y -
mMY);
922 TVectorD delta_p(P -
mMP);
926 mVPP.Rank1Update(delta_p, alpha);
927 mVPY.Rank1Update(delta_p, delta_y, alpha);
928 mVYY.Rank1Update(delta_y, alpha);
932 mMP += delta_p * beta;
933 mMY += delta_y * beta;
957 TVectorD delta_y(
mMY - rhs.
mMY);
958 TVectorD delta_p(
mMP - rhs.
mMP);
964 mVYY.Rank1Update(delta_y, alpha);
966 mVPY.Rank1Update(delta_p, delta_y, alpha);
968 mVPP.Rank1Update(delta_p, alpha);
972 mMY += delta_y * beta;
973 mMP += delta_p * beta;
985 if(i<0 || i >=
nP )
return -1;
987 mean =
mMP(i);
return 0;
996 if(i<0 || i >=
nY )
return -1;
998 mean =
mMY(i);
return 0;
1007 if(i<0 || i >=
nY )
return -1;
1009 mean =
mMYp(i);
return 0;
1018 if(i<0 || i >=
nP )
return -1;
1030 if(i<0 || i >=
nY )
return -1;
1041 if(i<0 || i >=
nY )
return -1;
1052 if( i>j) {
int k=i; i=j; j=k; }
1054 if(i<0 || i >=
nP )
return -11;
1066 if(ip<0 || ip >=
nP )
return -11;
1067 if(iy<0 || iy >=
nY )
return -12;
1078 if( i>j) {
int k=i; i=j; j=k; }
1080 if(i<0 || i >=
nY )
return -11;
1095 for (
size_t i = 1; i <dim; i++) {
1096 QwMessage << Form(
"P%d%11s",(
int)i,
" ");
1098 QwMessage << Form(
"\n mean sig(distrib) nSig(mean) correlation-matrix ....\n");
1099 for (
size_t i = 0; i <dim; i++) {
1105 if(sigI>0.) nSig=meanI/err;
1107 QwMessage << Form(
"P%d: %+12.4g %12.3g %.1f ",(
int)i,meanI,sigI,nSig);
1108 for (
size_t j = 1; j <dim; j++) {
1109 if( j<=i) {
QwMessage << Form(
" %12s",
"._._._.");
continue;}
1113 double corel=cov / sigI / sigJ;
1127 QwMessage << Form(
" j, mean, sig(mean), nSig(mean), sig(distribution) \n");
1129 for (
int i = 0; i <
nY; i++) {
1134 double nSigErr = meanI / err;
1135 QwMessage << Form(
"Y%02d, %+11.4g, %12.4g, %8.1f, %12.4g "" ",i,meanI,err,nSigErr,sigI)<<
QwLog::endl;
1147 QwMessage << Form(
"\n j slope sigma mean/sigma\n");
1148 for (
int iy = 0; iy <
nY; iy++) {
1150 for (
int j = 0; j <
nP; j++) {
1151 double val=
Axy(j,iy);
1152 double err=
dAxy(j,iy);
1153 double nSig=val/err;
1155 if(fabs(nSig)>3.) x=
'*';
1156 QwMessage << Form(
" slope_%d = %11.3g +/-%11.3g (nSig=%.2f) %c\n",j,val, err,nSig,x);
1170 for (
int i = 0; i <
nP; i++) {
1173 QwMessage << Form(
"\n j meanY sigY correlation with Ps ....\n");
1174 for (
int iy = 0; iy <
nY; iy++) {
1179 QwMessage << Form(
" %3d %6sY%d: %+12.4g %12.4g ",iy,
" ",iy,meanI,sigI);
1180 for (
int ip = 0; ip <
nP; ip++) {
1184 double corel = cov / sigI / sigJ;
1198 for (
int i = 0; i <
nY; i++){
1211 for (
int i = 0; i <
nY; i++){
1223for(
size_t i = 0; i <
fAllVar.size(); ++i){
1224 for(
size_t j = i; j <
fAllVar.size(); ++j){
1296 mVP = TMatrixDDiag(sigmaP);
1297 mVY = TMatrixDDiag(sigmaY);
1300 for(
size_t i = 0; i <
fAllVar.size(); ++i){
1301 for(
size_t j = i; j <
fAllVar.size(); ++j){
1313 TMatrixD mVYP_clean(TMatrixD::kTransposed, mVPY_clean);
1321 TMatrixD mSYP_clean(TMatrixD::kTransposed, mSPY_clean);
1323 TVectorD mSP_clean = TMatrixDDiag(mSPP_clean);
1326 TVectorD mSY_clean = TMatrixDDiag(mSYY_clean);
1332 if (
mRPP.Determinant() < std::pow(10,-(2*
nP))) {
1333 QwWarning <<
"LRB: correlation matrix nearly singular, "
1334 <<
"determinant = " <<
mRPP.Determinant()
1335 <<
" (set includes highly correlated variable pairs)"
1342 QwWarning <<
"LRB: solving failed (this happens when only few events)."
1350 TMatrixD invRPP(TMatrixD::kInverted,
mRPP);
1351 Axy = TMatrixD(invRPP, TMatrixD::kMult,
mRPY);
1353 Axy.NormByColumn(mSP_clean);
1355 Axy.NormByRow(mSY_clean,
"");
1363 mVYYp = mVYY_clean +
Ayx * mVPP_clean *
Axy - (
Ayx * mVPY_clean + mVYP_clean *
Axy);
1367 for (
int i = 0; i <
mVYp.GetNrows(); i++) {
1368 if (
mVYp(i) < 0 && fabs(
mVYp(i)) < 1e-12) {
1376 mSYYp = mSYY_clean +
Ayx * mSPP_clean *
Axy - (
Ayx * mSPY_clean + mSYP_clean *
Axy);
1391 dAxy.Rank1Update(TMatrixDDiag(invRPP), TMatrixDDiag(
mRYYp), norm);
1394 dAxy.NormByColumn(mSP_clean);
An options class which parses command line, config file and environment.
Decoding and management for VQWK ADC channels (6x32-bit datawords)
ROOT file and tree management wrapper classes.
Definition of the pure virtual base class of all data elements.
Parameter file parsing and management.
A logfile class, based on an identical class in the Hermes analyzer.
#define QwVerbose
Predefined log drain for verbose messages.
#define QwError
Predefined log drain for errors.
#define QwWarning
Predefined log drain for warnings.
#define QwMessage
Predefined log drain for regular messages.
Helicity pattern analysis and management.
const VQwHardwareChannel * RequestExternalPointer(const TString &name) const
const VQwHardwareChannel * RequestExternalPointer(const TString &name) const
Retrieve a direct pointer to an external variable Searches for the named variable in external subsyst...
static std::ostream & endl(std::ostream &)
End of the line.
Command-line and configuration file options processor.
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
Configuration file parser with flexible tokenization and search capabilities.
Bool_t PopValue(const std::string keyname, T &retvalue)
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
void TrimComment(const char commentchar)
std::string GetNextToken(const std::string &separatorchars)
Get next token as a string.
A wrapper class for a ROOT file or memory mapped file.
void NewTree(const std::string &name, const std::string &desc)
Create a new tree with name and description.
TTree * GetTree(const std::string &name)
Get the tree with name.
Abstract base for concrete hardware channels implementing dual-operator pattern.
std::ofstream fAliasOutputFile
std::string fAliasOutputFileSuff
void printSummaryAlphas() const
void printSummaryMeansWithUncCorrected() const
Int_t getSigmaP(const int i, Double_t &sigma) const
Get mean value of a variable, returns error code.
Int_t fErrorFlag
is information valid
TMatrixD mVPY
unnormalized covariances
std::vector< const VQwHardwareChannel * > fAllVar
TMatrixD mSPY
normalized covariances
GrandCorrelator & operator+=(const std::pair< TVectorD, TVectorD > &rhs)
std::string fAliasOutputFileBase
Int_t getMeanY(const int i, Double_t &mean) const
void ClearEventData() override
std::vector< double > fAllValues
void printSummaryMeansWithUnc() const
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
Int_t ConnectChannels(QwSubsystemArrayParity &asym, QwSubsystemArrayParity &diff) override
Connect to Channels (asymmetry/difference only)
std::vector< std::vector< TH2D > > fH2dv
std::string fAliasOutputPath
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.
std::vector< TH1D > fH1dv
TMatrixD mRPY
correlations
Subsystem array container specialized for parity analysis with asymmetry calculations.
const UInt_t * GetEventcutErrorFlagPointer() const
std::vector< std::string > fDependentFull
void AccumulateRunningSum()
void SetEventcutErrorFlagPointer(const UInt_t *errorflagptr)
std::vector< Double_t > fDependentValues
virtual void ParseConfigFile(QwParameterFile &file)
std::vector< const VQwHardwareChannel * > fDependentVar
UInt_t GetEventcutErrorFlag() const
VQwDataHandler(const TString &name)
std::string ParseSeparator
std::pair< EQwHandleType, std::string > ParseHandledVariable(const std::string &variable)
std::vector< EQwHandleType > fDependentType
std::vector< std::string > fDependentName