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++){
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.
//<========= 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
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.