Histo with array

Hi,

  I want to define many historgrams in my program. For the moment i am doing it like this:

//declare my histogram
TH1F *JetPt_[2][3][3];

//string goes with histo name for different data filling
TString SAMP[2]={“GJ_”,“JJ_”};
TString WJET[3]={“LJ_”,“SJ_”,“TJ_”};
TString NJET[3]={“1JS_”,“2JS_”,“3JS_”};

//Then I run loop of s, nj and wj over the code below
for(int s=0;s<2;s++){
for(int wj=0;wj<3;wj++){
for(int nj=0;nj<3;nj++){

char pt1[50];
sprintf(pt1,"%s%s%s%s%s",“JetPt_”,SAMP[s],NJET[nj],WJET[wj],"\0");
JetPt_[s][nj][wj]=new TH1F(pt1,pt1,pt_nbin,pt_lo,pt_up);
}}}

I do not know to make it work how to change thess two ines??

TH1F *JetPt_[2][3][3];
JetPt_[s][nj][wj]=new TH1F(pt1,pt1,pt_nbin,pt_lo,pt_up);

NOTE: I tried with it but give segmentation falt.

Thanks and with best,
sushil

If you expect an answer, you should post the shortest possible RUNNING script reproducing your problem. Please use the “code” option when posting plain code in the message.

Rene

Hi,

I have kept the possible shortest script at the following location:

schauhan.web.cern.ch/schauhan/B … ned_Short/

with best,
sushil

Sorry I could not able to put the input root file as it is of size 2.5 GB. But I tried to run it and the output is put in the “log” files.

with best,
sushil

Well, I cannot execute your code, but I see two potential problems. See corrected code below and in particular the lines with “//<========”

Rene

[code]#include “TH1.h”

void sus() {
//declare my histogram
TH1F *Jet_Pt_[2][3][3]; //<========

//strings to be pass to histo names
TString SAMP[2]={“GJ_”,“JJ_”};
TString WJET[3]={“LJ_”,“SJ_”,“TJ_”};
TString NJET[3]={“1JS_”,“2JS_”,“3JS_”};

//Bin numbers and range are defined here
Double_t pt_lo;
Double_t pt_up;
Int_t pt_nbin;

//Initiliaze the histo variables

pt_lo=0.0;
pt_up=4000.0;
pt_nbin=400;

//Jet Kinematics

for(int s=0;s<2;s++){
for(int wj=0;wj<3;wj++){
for(int nj=0;nj<3;nj++){

char pt[50];

//<========= changes in the following line
sprintf(pt,"%s%s%s%s%s",“Jet_Pt_”,SAMP[s].Data(),NJET[nj].Data(),WJET[wj].Data(),"\0"); //<---- Strings are added her to histo name
Jet_Pt_[s][nj][wj]=new TH1F(pt,pt,pt_nbin,pt_lo,pt_up);

}//Njet_upto
}//which jet
}//loop over sample type

}
[/code]

Hi,

Thanks a lot. It solves the problem. 

  Just want to know what exactly ".Data()" does here?

with best,
sushil

your variables like SAMP are TString and sprintf does not know anything about TString, only about char*. The Data(0 function returns the char* of the TString.

Rene