59 "print correlations after determining them");
78 QwWarning <<
"QwCorrelatorNew: expect 0 <= block <= 3 but block = "
138 QwWarning <<
"QwCorrelatorNew::AccumulateRunningSum "
139 <<
"can only accept other QwCorrelatorNew objects."
147 if (
nP == 0 ||
nY == 0) {
161 <<
"< 1% good events, "
168 QwVerbose <<
" Entries failed due to error flag: "
223 std::pair<EQwHandleType,std::string> type_name;
237 if (primary_token ==
"iv") {
242 else if (primary_token ==
"dv") {
247 else if (primary_token ==
"treetype") {
251 QwError <<
"LoadChannelMap in QwCorrelatorNew read invalid primary_token " << primary_token <<
QwLog::endl;
285 QwWarning <<
"QwCorrelatorNew::ConnectChannels(QwSubsystemArrayParity& asym, QwSubsystemArrayParity& diff): "
287 <<
", for asym/diff correlator does not have proper type, type=="
293 QwWarning <<
"QwCombiner::ConnectChannels(QwSubsystemArrayParity& asym, QwSubsystemArrayParity& diff): Dependent variable, "
295 <<
", was not found (fullname=="
323 QwWarning <<
"Independent variable for correlator has unknown type."
354 const std::string& treeprefix,
355 const std::string& branchprefix)
358 if (
nP == 0 ||
nY == 0) {
373 const std::string name = treeprefix +
fTreeName;
377 if (
fTree == NULL)
return;
384 fTree->Branch(TString(branchprefix +
"ErrorFlag"), &(this->
fErrorFlag));
386 auto bn = [&](
const TString& n) {
387 return TString(branchprefix + n);
389 auto pm = [](TMatrixD& m) {
390 return m.GetMatrixArray();
392 auto lm = [](TMatrixD& m,
const TString& n) {
393 return Form(
"%s[%d][%d]/D", n.Data(), m.GetNrows(), m.GetNcols());
395 auto branchm = [&](TTree* tree, TMatrixD& m,
const TString& n) {
396 tree->Branch(bn(n),pm(m),lm(m,n));
398 auto pv = [](TVectorD& v) {
399 return v.GetMatrixArray();
401 auto lv = [](TVectorD& v,
const TString& n) {
402 return Form(
"%s[%d]/D", n.Data(), v.GetNrows());
404 auto branchv = [&](TTree* tree, TVectorD& v,
const TString& n) {
405 tree->Branch(bn(n),pv(v),lv(v,n));
446 if (
nP == 0 ||
nY == 0) {
452 name.ReplaceAll(
" ",
"_");
453 folder->mkdir(name)->cd();
457 for (
int i = 0; i <
nP; i++) {
462 fH1iv[i].GetXaxis()->SetNdivisions(4);
468 for (
int i = 0; i <
nP; i++) {
470 for (
int j = i+1; j <
nP; j++) {
473 Form(
"iv correlation P%d_P%d, pass=%s ;P%d=%s (ppm);P%d=%s (ppm) ",
477 fH2iv[i][j].GetXaxis()->SetTitleColor(kBlue);
478 fH2iv[i][j].GetYaxis()->SetTitleColor(kBlue);
479 fH2iv[i][j].GetXaxis()->SetNdivisions(4);
480 fH2iv[i][j].GetYaxis()->SetNdivisions(4);
486 for (
int i = 0; i <
nY; i++) {
491 fH1dv[i].GetXaxis()->SetNdivisions(4);
497 for (
int i = 0; i <
nP; i++) {
499 for (
int j = 0; j <
nY; j++) {
502 Form(
"iv-dv correlation P%d_Y%d, pass=%s ;P%d=%s (ppm);Y%d=%s (ppm) ",
506 fH2dv[i][j].GetXaxis()->SetTitleColor(kBlue);
507 fH2dv[i][j].GetYaxis()->SetTitleColor(kBlue);
508 fH2dv[i][j].GetXaxis()->SetNdivisions(4);
509 fH2dv[i][j].GetYaxis()->SetNdivisions(4);
515 fHnames[0] = TH1D(
"NamesIV",Form(
"IV name list nIV=%d",
nP),
nP,0,1);
516 for (
int i = 0; i <
nP; i++)
518 fHnames[1] = TH1D(
"NamesDV",Form(
"DV name list nIV=%d",
nY),
nY,0,1);
519 for (
int i = 0; i <
nY; i++)
530 if (
nP == 0 ||
nY == 0) {
556 this->
Axy.Write(
"slopes");
557 this->
dAxy.Write(
"sigSlopes");
559 this->
mRPP.Write(
"IV_IV_correlation");
560 this->
mRPY.Write(
"IV_DV_correlation");
561 this->
mRYY.Write(
"DV_DV_correlation");
562 this->
mRYYp.Write(
"DV_DV_correlation_prime");
564 this->
mMP.Write(
"IV_mean");
565 this->
mMY.Write(
"DV_mean");
566 this->
mMYp.Write(
"DV_mean_prime");
571 Mstat.Write(
"MyStat");
574 TH1D hiv(
"IVname",
"names of IVs",
nP,-0.5,
nP-0.5);
579 TH1D hdv(
"DVname",
"names of IVs",
nY,-0.5,
nY-0.5);
584 this->
mSP.Write(
"IV_sigma");
585 this->
mSY.Write(
"DV_sigma");
586 this->
mSYp.Write(
"DV_sigma_prime");
589 this->
mVPP.Write(
"IV_IV_rawVariance");
590 this->
mVPY.Write(
"IV_DV_rawVariance");
591 this->
mVYY.Write(
"DV_DV_rawVariance");
592 this->
mVYYp.Write(
"DV_DV_rawVariance_prime");
593 TVectorD mVY2(TMatrixDDiag(this->
mVYY));
594 mVY2.Write(
"DV_rawVariance");
595 TVectorD mVP2(TMatrixDDiag(this->
mVPP));
596 mVP2.Write(
"IV_rawVariance");
597 TVectorD mVY2prime(TMatrixDDiag(this->
mVYYp));
598 mVY2prime.Write(
"DV_rawVariance_prime");
601 this->
mSPP.Write(
"IV_IV_normVariance");
602 this->
mSPY.Write(
"IV_DV_normVariance");
603 this->
mSYY.Write(
"DV_DV_normVariance");
604 this->
mSYYp.Write(
"DV_DV_normVariance_prime");
605 TVectorD sigY2(TMatrixDDiag(this->
mSYY));
606 sigY2.Write(
"DV_normVariance");
607 TVectorD sigX2(TMatrixDDiag(this->
mSPP));
608 sigX2.Write(
"IV_normVariance");
609 TVectorD sigY2prime(TMatrixDDiag(this->
mSYYp));
610 sigY2prime.Write(
"DV_normVariance_prime");
612 this->
Axy.Write(
"A_xy");
613 this->
Ayx.Write(
"A_yx");
621 std::string file = path + name;
622 fAlphaOutputFile =
new TFile(TString(file),
"RECREATE",
"correlation coefficients");
635 std::replace(label.begin(), label.end(),
'.',
'_');
639 std::string file = path + name +
".C";
642 fAliasOutputFile << Form(
"void %s(int i = 0) {", name.c_str()) << std::endl;
677 fAliasOutputFile << Form(
" TTree* tree = (TTree*) gDirectory->Get(\"mul\");") << std::endl;
678 for (
int i = 0; i <
nY; i++) {
681 for (
int j = 0; j <
nP; j++) {
835 const TVectorD& P = rhs.first;
836 const TVectorD& Y = rhs.second;
850 TVectorD delta_y(Y -
mMY);
851 TVectorD delta_p(P -
mMP);
855 mVPP.Rank1Update(delta_p, alpha);
856 mVPY.Rank1Update(delta_p, delta_y, alpha);
857 mVYY.Rank1Update(delta_y, alpha);
861 mMP += delta_p * beta;
862 mMY += delta_y * beta;
886 TVectorD delta_y(
mMY - rhs.
mMY);
887 TVectorD delta_p(
mMP - rhs.
mMP);
893 mVYY.Rank1Update(delta_y, alpha);
895 mVPY.Rank1Update(delta_p, delta_y, alpha);
897 mVPP.Rank1Update(delta_p, alpha);
901 mMY += delta_y * beta;
902 mMP += delta_p * beta;
915 if(i<0 || i >=
nP )
return -1;
917 mean =
mMP(i);
return 0;
926 if(i<0 || i >=
nY )
return -1;
928 mean =
mMY(i);
return 0;
937 if(i<0 || i >=
nY )
return -1;
939 mean =
mMYp(i);
return 0;
948 if(i<0 || i >=
nP )
return -1;
960 if(i<0 || i >=
nY )
return -1;
971 if(i<0 || i >=
nY )
return -1;
982 if( i>j) {
int k=i; i=j; j=k; }
984 if(i<0 || i >=
nP )
return -11;
996 if(ip<0 || ip >=
nP )
return -11;
997 if(iy<0 || iy >=
nY )
return -12;
1008 if( i>j) {
int k=i; i=j; j=k; }
1010 if(i<0 || i >=
nY )
return -11;
1025 for (
size_t i = 1; i <dim; i++) {
1026 QwMessage << Form(
"P%d%11s",(
int)i,
" ");
1028 QwMessage << Form(
"\n mean sig(distrib) nSig(mean) correlation-matrix ....\n");
1029 for (
size_t i = 0; i <dim; i++) {
1035 if(sigI>0.) nSig=meanI/err;
1037 QwMessage << Form(
"P%d: %+12.4g %12.3g %.1f ",(
int)i,meanI,sigI,nSig);
1038 for (
size_t j = 1; j <dim; j++) {
1039 if( j<=i) {
QwMessage << Form(
" %12s",
"._._._.");
continue;}
1043 double corel=cov / sigI / sigJ;
1058 QwMessage << Form(
" j, mean, sig(mean), nSig(mean), sig(distribution) \n");
1060 for (
int i = 0; i <
nY; i++) {
1065 double nSigErr = meanI / err;
1066 QwMessage << Form(
"Y%02d, %+11.4g, %12.4g, %8.1f, %12.4g "" ",i,meanI,err,nSigErr,sigI)<<
QwLog::endl;
1078 QwMessage << Form(
"\n j slope sigma mean/sigma\n");
1079 for (
int iy = 0; iy <
nY; iy++) {
1081 for (
int j = 0; j <
nP; j++) {
1082 double val=
Axy(j,iy);
1083 double err=
dAxy(j,iy);
1084 double nSig=val/err;
1086 if(fabs(nSig)>3.) x=
'*';
1087 QwMessage << Form(
" slope_%d = %11.3g +/-%11.3g (nSig=%.2f) %c\n",j,val, err,nSig,x);
1101 for (
int i = 0; i <
nP; i++) {
1104 QwMessage << Form(
"\n j meanY sigY correlation with Ps ....\n");
1105 for (
int iy = 0; iy <
nY; iy++) {
1110 QwMessage << Form(
" %3d %6sY%d: %+12.4g %12.4g ",iy,
" ",iy,meanI,sigI);
1111 for (
int ip = 0; ip <
nP; ip++) {
1115 double corel = cov / sigI / sigJ;
1129 for (
int i = 0; i <
nY; i++){
1142 for (
int i = 0; i <
nY; i++){
1176 if (
mRPP.Determinant() < std::pow(10,-(2*
nP))) {
1177 QwWarning <<
"LRB: correlation matrix nearly singular, "
1178 <<
"determinant = " <<
mRPP.Determinant()
1179 <<
" (set includes highly correlated variable pairs)"
1186 QwWarning <<
"LRB: solving failed (this happens when only few events)."
1191 TMatrixD invRPP(TMatrixD::kInverted,
mRPP);
1192 Axy = TMatrixD(invRPP, TMatrixD::kMult,
mRPY);
1216 dAxy.Rank1Update(TMatrixDDiag(invRPP), TMatrixDDiag(
mRYYp), norm);
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.
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
Int_t getSigmaYprime(const int i, Double_t &sigma) const
std::vector< TH1D > fHnames
static void DefineOptions(QwOptions &options)
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)
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.
std::string fAlphaOutputFileSuff
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
void ProcessOptions(QwOptions &options)
std::string fAliasOutputFileSuff
static bool fPrintCorrelations
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.
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