Set name for TH2 plots

Hi

I am trying to fill some TH2 plots , but I am having crashes if

 TH2F * plot[variables_.size()];

  for (unsigned int j = 0; j < variables_.size (); j++){

  char number[100];

  sprintf(number,"[%s]",variables_[j].first.c_str());

//variables_[j].first is the name of the variable

  plot[j] =  new TH2F( "plot["+j+"]"," Some plots for variables", variables_.size(),0,variables_.size(),10,0,1);


  plot[j]->Fill( j, variables_[j].second);

}

So, apparently, I am doing something wrong in the

plot[j] = new TH2F( “plot[”+j+"]"," Some plots for variables", variables_.size(),0,variables_.size(),10,0,1);

– What is the proper syntax, so, I will create different TH2 histos following the j counting?

Thanks in advance

Hi,

Use plot[j] = new TH2F( TString::Format("plot[%d]",j) ," Some plots for variables", variables_.size(),0,variables_.size(),10,0,1);

Philippe.