Problem getting linear correlation from TH2 using TBranches

Hi

I am trying to loop inside TBranches so that to get the correlation of “all with all”

 
  TObjArray *Branches_Sgn = tree_Signal->GetListOfBranches ();

  Int_t Entries_Sgn = Branches_Sgn->GetEntries ();
    char Name_Sgnl_[100];
    char Name_Sgnl2_[100];
  
  for (Int_t i = 0; i < Entries_Sgn; i++) {

    TBranch *Branch_Sgnl_ = (TBranch *) Branches_Sgn->At (i);

    

    sprintf (Name_Sgnl_, "%s", Branch_Sgnl_->GetName ());

    for (Int_t j = 0; j < Entries_Sgn; j++) {

      TBranch *Branch_Sgnl2_ = (TBranch *) Branches_Sgn->At (j);

      sprintf (Name_Sgnl2_, "%s", Branch_Sgnl2_->GetName ());

      tree_Signal->Draw (Form ("%s:%s>>hcorr", Name_Sgnl_, Name_Sgnl2_, "", "goff"));

      TH2 *hcorr = (TH2 *) gDirectory->Get ("hcorr");

      cout << "The correlation is..." << Name_Sgnl_ << " with " << Name_Sgnl2_ << "   correl factor =   " << '\t' << hcorr->GetCorrelationFactor () << endl;

      float hCorr = hcorr->GetCorrelationFactor ();

      all_correlation_table_.push_back(pair <string, float > (Name_Sgnl_,hCorr));

      if (fabs (hCorr) > cor_cut && Name_Sgnl_ != Name_Sgnl2_ && j > i) {
        high_correlation_matrix_.push_back (pair < string, string > (Name_Sgnl_,Name_Sgnl2_));
      }

    }
  }

The problem is that I get “0” even for the correlation of the var:var which should be 1 is something like

The correlation is...btagT with btagT correl factor = 0
What am I doing wrong ?

thanks

Alex

Hi again

ok…so looks like the using repetitively “>>hcorr” causes this problem - Instead, this code works smoothly

[code]for (unsigned int i = 0; i < Entries_Sgn; i++) {

TBranch *Branch_Sgnl_ = (TBranch *) Branches_Sgn->At (i);

sprintf (Name_Sgnl_, "%s", Branch_Sgnl_->GetName ());

for (unsigned int j = 0; j < Entries_Sgn; j++) {

  TBranch *Branch_Sgnl2_ = (TBranch *) Branches_Sgn->At (j);

  sprintf (Name_Sgnl2_, "%s", Branch_Sgnl2_->GetName ());

  tree_Signal->Draw (Form ("%s:%s>>hcorr_%i%i", Branch_Sgnl_->GetName (), Branch_Sgnl2_->GetName(),i,j,"","goff"));

  sprintf(nn,"hcorr_%i%i",i,j);
  TH2 *hcorr_ = (TH2 *) gDirectory->Get (nn);

  float hCorrs = -100;hCorrs= hcorr_->GetCorrelationFactor ();

  if (fabs (hCorrs) > cor_cut && Name_Sgnl_ != Name_Sgnl2_ && j > i) {
    high_correlation_matrix_.push_back (pair < string, string > (Name_Sgnl_,Name_Sgnl2_));
  }
  delete hcorr_;

[/code]