Dear Rooters,
I recently posted a question about opening a large number of root-files containing histograms and after help from Rene and Axel this now works. However I have found a new problem with my macro.
The intension of opening all these files is to add the histograms together and investigate the variance between them. I loop over the 500 files with histograms, and the fist time I take a copy of the first histogram and then I add the other 499 histgrams using Add. I had this macro under windows and it produced outputs that I believe where correct. However I have now changed to Ubuntu and no things don’t work anymore (I still have the same root version 5.18 ). The final (total) histogram looks more like one randomly selected histogram of the 500 than the total of them. When I merge the histograms using hadd it looks good so I trust my input files to be ok, but hadd doesn’t give me the variance of the histograms, so I would really like my own macro to work!
I am most grateful for any help concerning this!
Regards,
Karin
void TEST(){
//This is a test macro
TH1::AddDirectory(kFALSE);
//Declaring some global objects
TH1F *h_PE;
char fluence[1000];
//Loop over 500 histograms to see if the avarage is correct
for(int iR=1000; iR<1500;iR++){
sprintf(fluence, "/media/FREECOM\ HDD/DATA/Emax8MeV/VRT/plots/spectra/histos/histos_Spectrum_Water_xCoord_0cm_yCoord_0cm_depth_10.05cm_Elekta6MV_%u.root", iR);
TFile* fluenceFile = TFile::Open(fluence,"read");
cout<<"Opened file: "<<fluence<<endl;
if(iR==1000){
h_PE = new TH1F(*h_primaryElectronFluenceSpectrum); //the histogram in the root-file is called h_primaryElectronFluenceSpectrum.
h_PE->SetName("h_PE");
}
else if(iR>1000){
h_PE->Add(h_primaryElectronFluenceSpectrum);
}
delete fluenceFile;
}//end loop over files
}//end macro