Char to histogram?

How would I go about making a “char” valued object, a histogram valued one. Here is my code:

[code]char h [100];
sprintf (h, “File_%d”, om[i]);

        int overf=h.GetNbinsX()+1;

[/code]

The histogram is “File _%d”, when I use the sprintf and create my char of “h” it makes it so that the “h” has a value of char. How would I make it so that it goes back to having a property of a histogram?

At least tell me if the question is not understood or if its just stupid.
Thanks

I apologize if this is a noobish question

Honestly speaking I have no earthly idea what’s your goal.

Haha didn’t think anyone would. I have a set of histograms, now I am running a for loop to analyze all of the with each iteration. To change the name of the histogram, I am using the sprintf command which will print the name of each histogram by altering the one distinct part of the name. But when I use the command, i need to use char *const [100] which creates a constant that is valued “char”. That constant now takes the place of the histogram name. So now, later in the loop when I want to analyze the histogram OR *const, it can’t be, because it’s not looked at as a histogram, it’s looked at as a character.

Does that make more sense?

Where do these histograms reside? In RAM? In a ROOT file?
Do you know the exact “type” of your histograms (i.e. is each of them a TH1F / TH1D / TH2F / TH2D / …)?
Or do different “names” point to different “types” of histograms?

[quote=“Wile E. Coyote”]Where do these histograms reside? In RAM? In a ROOT file?
Do you know the exact “type” of your histograms (i.e. is each of them a TH1F / TH1D / TH2F / TH2D / …)?
Or do different “names” point to different “types” of histograms?[/quote]

They’re located in a root file yes. They are all TH1F. All the same type of histogram, just different data inside.

[code]TFile *MyRootFilePointer = TFile::Open(“MyRootFile.root”);

char name[100];
TH1F *pointer = ((TH1F *)0);

for (int i = StartValue; i < EndValue; i++) {
// build the “name” of the histogram
snprintf(name, sizeof(name), “File_%d”, om[i]);

// get the histogram from the ROOT file
if (MyRootFilePointer) MyRootFilePointer->GetObject(name, pointer);
if (!pointer) {
std::cout << “TH1F : " << name << " : NOT found!” << std::endl;
continue; // next “i”
}

// histogram found …
int overf = pointer->GetNbinsX() + 1;
std::cout << "TH1F : " << name << " : overf = " << overf << std::endl;
pointer->Draw(); // … draw it
} // end of the “for” loop[/code]

So really it’s just a matter of creating a pointer for the histogram that will be called on later in the program?

Retrieving Objects from Disk
Subdirectories and Navigation

Tried this and when I ran the program I got the error message:

Error: illegal pointer to class object point 0x0 152

Hi,

Most likely the histogram name is slightly different from what you expect. If you did not yet resolve this issue, please provide the content of your file and your script.

Cheers,
Philippe.