Problem using Form() for an array with in the TTree:Draw method while using it on a for loop

Please provide the following information:


ROOT Version (e.g. 6.12/02):
Platform, compiler (e.g. MacOSX 10.12.6, gcc4):


Hi all,

I have data on a TTree, which contains different Branches, like, Charge, MaxAmp, distance, etc, etc, for a number of channels I have. For example, for each event given if I have 4 channels, I will store:

IntOffset00, IntOffset01, IntOffset02, IntOffset03,
MaxAmp00, MaxAmp01, MaxAmp02, MaxAmp03, etc
each one of this is already a branch saved by the main().

TCanvas *cCorrelation = new TCanvas("Correlation","Correlation",1200,1200);
  cCorrelation->Divide(2,2);
  TH2F *corrTH2F[4];
  for (Int_t i=0 ; i<nCh ; i++) {
      corrTH2F[i] = new TH2F(Form("Max Amplitude vs. non-noisy Charge in Ch%02d",i),"; Integrated Charge [A.U] ; Amplitud [V]",128,-10,70,128,-0.1,1.00);
      cCorrelation->cd(i+1);
      tSiPM->Draw(Form("MaxAmp%02d:IntOffset%02d>>corrTH2F[%i]",i,i,i),"","COLZ");
  }

As you can see, I defined a TH2F array called corrTH2F[i], in which I will store my correlation histograms which are defined in the loop. Then I use the TTree:Draw() and the Form() method to draw my histograms. I expected that my histograms where store in the corrTH2F[i] elementes but apparently what it does is actually creating new 2D histograms named corrTH2F[%i], so the corrTH2F[i] and there properties are omited (axis labels, axis ranges, names, etc, etc), see attached figure.

How could I avoid this problem?

Thank you in advance for any possible suggestion.

Best regards,

David

Then what I wanted to do is to plot the correlation of this branches, for example, in this manner:

It seems your post has been truncated somehow …

Hi,
For have noticed it.
I did up-dated the post!

Cheers!

I think you cannot put an array element as histogram after >> … it should be a “plain” histogram.
you can name it corrTH2F%i

1 Like

Are you suggesting something like this?

      TH2F Form("corrTH2F%02d",i) = new TH2F(Form("Max Amplitude vs. non-noisy Charge in Ch%02d",i),"; Integrated Charge [A.U] ; Amplitud [V]",nPhE,cntmin,cntmax,nbins_volt,v_low,v_up);

inside the for loop? will TH2F Form(“corrTH2F%02d”,i) work? is it allowed?

thanks!

no no … something like that:

  for (Int_t i=0 ; i<nCh ; i++) {
      corrTH2F[i] = new TH2F(Form("Max Amplitude vs. non-noisy Charge in Ch%02d",i),"; Integrated Charge [A.U] ; Amplitud [V]",128,-10,70,128,-0.1,1.00);
      cCorrelation->cd(i+1);
      tSiPM->Draw(Form("MaxAmp%02d:IntOffset%02d>>corrTH2F%i",i,i,i),"","COLZ");
  }

it will create the histograms:

corrTH2F0, corrTH2F1, corrTH2F2 … etc

I agree that :

tSiPM->Draw(Form("MaxAmp%02d:IntOffset%02d>>corrTH2F%i",i,i,i),"","COLZ");

will create new histograms corrTH2F%i : corrTH2F0, corrTH2F1, corrTH2F2

However, I don’t see how these will be related to corrTH2F[i] histograms. Do we agree on that?

You are right … they won’t be … See:

root [0] TH1F h[4]
(TH1F [4]) { @0x7ffcc3c9d420, @0x7ffcc3c9d808, @0x7ffcc3c9dbf0, @0x7ffcc3c9dfd8 }
root [1] ntuple->Draw("px>>h[0]")
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [2] .ls
TFile**		hsimple.root	Demo ROOT file with histograms
 TFile*		hsimple.root	Demo ROOT file with histograms
  OBJ: TH1F		 : 0 at: 0x7ffcc3c9d420
  OBJ: TH1F		 : 0 at: 0x7ffcc3c9d808
  OBJ: TH1F		 : 0 at: 0x7ffcc3c9dbf0
  OBJ: TH1F		 : 0 at: 0x7ffcc3c9dfd8
  OBJ: TNtuple	ntuple	Demo ntuple : 0 at: 0x7ffcc4761c40
  OBJ: TH1F	h[0]	px : 0 at: 0x7ffcc7935550
  KEY: TNtuple	ntuple;1	Demo ntuple
root [3] 

It creates the histogram with name h[0] … The histogram after >> cannot be an array element.

1 Like

Thank you for your ideas, I don’t really want to play these memories. But our conversation made me think about mixing “plain histogram” idea with the Form() idea, since in ROOT the names of the TObject should be unique, even if the variable name is the same (in this case: my pointer to corrTH2F), the names of the TObject will be different thanks to Form(“CorrTH2F%02d”,i) :

TCanvas *cCorrelation = new TCanvas("Correlation","Correlation",1200,1200);
  cCorrelation->Divide(2,2);
  for (Int_t i=0 ; i<nCh ; i++) {
      TH2F *corrTH2F = new TH2F(Form("CorrTH2F%02d",i),"; Integrated Charge [A.U] ; Amplitud [V]",nPhE,cntmin,cntmax,nPhE,v_low,v_up);
      cCorrelation->cd(i+1);
      tSiPM->Draw(Form("MaxAmp%02d:IntOffset%02d>>CorrTH2F%02d",i,i,i),"","COLZ");
      corrTH2F->Write(Form("CorrTH2F%02d",i));
  }

This works, as far as I computed, preserving the histogram predefined axis settings and so on.

Best regards,

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