Some histograms are stacked while others are not

Hello @couet ,
I have a file (Stack_Hist_signals.C) that stack some histgrams but others nothing.Also
appear me warnning message suchtat

"  Error in <HandleInterpreterException>: Trying to access a pointer that points to an invalid memory address. Execution of your code was aborted. In file included from input_line_8:1: /home/ahmed/bb-  _Signals/Stack_Hist_Signals.C:147:6: warning: invalid memory pointer passed to a callee:
     hmc[0][i]->SetLineColor(kYellow);  " 
     ^~~~~~~~~

I will send you the used root file and Stack_Hist_Signal.C to manage help me

thanks,
Ahmed
h90BP1_bb.root (84.1 KB)
Stack_Hist_Signals.C (9.7 KB)

The error message is clear, at least one of the “hmc[0][i]” is not found in the file. Check that all exist indeed; open the root file in a TBrowser and check or, e.g. in the code,

     //...
     hmc[0][i] = (TH1F*)rootH0BBbar->Get(hname_mc[i]);
     if (!hmc[0][i]) {
        cout << hname_mc[i] <<" not found" << endl;
        return;
     }
     //...
2 Likes

Hi,

$ root -l h90BP1_bb.root -e ".ls" -q

gives the following (I show only the lines relevant to the issue):

  KEY: TH1D      fatJet_PT;1       fatJet_PT distribution
  KEY: TH1D         fatJet_Eta;1          fatJet_Eta distribution
  KEY: TH1D     fatJet_Mass;1    fatJet_Mass distribution
  KEY: TH1D     fatJet_DeltaEta;1       fatJet_DeltaEta  distribution
  KEY: TH1D     fatJet_DeltaPhi;1       fatJet_DeltaPhi distribution

Mind these leading spaces in the names of the first two histograms - this is no bueno, and these are the primary reason for the crash.

1 Like
void AddToStack(const char *obj_name, THStack *st, TFile *F) {
   TList *L = (TList *)F->GetListOfKeys();
   TKey  *K = (TKey *)L->FindObject(obj_name);
   if (K) {
      TH1D  *H = (TH1D*)K->ReadObj();;
      st->Add(H);
   } else {
      printf("[%s] not found\n",obj_name);
   }
}

void Stack_Hist_Signals() {
   gStyle->SetOptStat(0);
   TFile *F = new TFile("h90BP1_bb.root");

   auto st = new THStack();


   AddToStack("    fatJet_Eta",st,F);
   AddToStack("  missingEt_Phi",st,F);
   AddToStack(" fatJet_EhadOverEem",st,F);
   AddToStack(" fatJet_PT",st,F);
   AddToStack(" missingET_MET",st,F);
   AddToStack("b1_eta",st,F);
   AddToStack("b1_pt",st,F);
   AddToStack("b2_eta",st,F);
   AddToStack("b2_pt",st,F);
   AddToStack("DR_b",st,F);
   AddToStack("fatJet_DeltaEta",st,F);
   AddToStack("fatJet_DeltaPhi",st,F);
   AddToStack("fatJet_Mass",st,F);
   AddToStack("h_eta",st,F);
   AddToStack("h_mass",st,F);
   AddToStack("h_pt",st,F);
   AddToStack("scalarHT_HT",st,F);

   auto c= new TCanvas();
   c->SetLogy();
   st->Draw("PMC PLC nostack");
}

1 Like

or:

...
   auto c= new TCanvas();
   c->SetLogy();
   st->Draw("PMC PLC HIST nostack");
   c->BuildLegend(0.5,0.35,0.8,0.85);
...

1 Like

thanks alot for a great efforts with me . The problem is solved

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.