Empty graphic and value of the graphic not zero


ROOT Version: 5.34.36
Platform: UBUNTU 16.04
Compiler: Not Provided


I have code bellow:

#include "TROOT.h"
#include "TMath.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TTree.h"
#include "TGraph.h"
#include "TBrowser.h"
#include "TH1.h"
#include "TF1.h"
#include "TH2.h"
#include "TRandom.h"
#include "TStopwatch.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

void sumStep(){  /// fecha linha 175
Int_t mm=0;
Double_t sum1=0;

// read a tree already done

      // defined a chain and added

      	TChain fChain("SamSIA8el"); //geometry samp1.geom 0.0
      
 	fChain.Add("SamSIA8el_tree_1000.root"); fChain.Add("SamSIA8el_tree_1001.root"); /*fChain.Add("SamSI_tree_1002.root"); 
 	fChain.Add("SamSI_tree_1003.root"); fChain.Add("SamSI_tree_1004.root"); fChain.Add("SamSI_tree_1005.root"); 
	fChain.Add("SamSI_tree_1006.root"); fChain.Add("SamSI_tree_1007.root"); fChain.Add("SamSI_tree_1008.root"); 
 	fChain.Add("SamSI_tree_1009.root"); fChain.Add("SamSI_tree_1010.root"); fChain.Add("SamSI_tree_1011.root");
	fChain.Add("SamSI_tree_1012.root"); fChain.Add("SamSI_tree_1013.root"); fChain.Add("SamSI_tree_1014.root"); 
 	fChain.Add("SamSI_tree_1015.root"); fChain.Add("SamSI_tree_1016.root"); fChain.Add("SamSI_tree_1017.root"); 
 	fChain.Add("SamSI_tree_1018.root"); fChain.Add("SamSI_tree_1019.root"); fChain.Add("SamSI_tree_1020.root"); 
 	fChain.Add("SamSI_tree_1021.root"); fChain.Add("SamSI_tree_1022.root"); fChain.Add("SamSI_tree_1023.root");
 	fChain.Add("SamSI_tree_1024.root"); fChain.Add("SamSI_tree_1025.root"); fChain.Add("SamSI_tree_1026.root"); 
 	fChain.Add("SamSI_tree_1027.root"); fChain.Add("SamSI_tree_1028.root"); fChain.Add("SamSI_tree_1029.root"); 
 	fChain.Add("SamSI_tree_1030.root"); fChain.Add("SamSI_tree_1031.root"); fChain.Add("SamSI_tree_1032.root"); 

 	fChain.Add("SamSI_tree_1033.root"); fChain.Add("SamSI_tree_1034.root"); fChain.Add("SamSI_tree_1035.root");
 	fChain.Add("SamSI_tree_1036.root"); fChain.Add("SamSI_tree_1037.root"); fChain.Add("SamSI_tree_1038.root"); 
 	fChain.Add("SamSI_tree_1039.root"); fChain.Add("SamSI_tree_1040.root"); fChain.Add("SamSI_tree_1041.root"); 
 	fChain.Add("SamSI_tree_1042.root"); fChain.Add("SamSI_tree_1043.root"); fChain.Add("SamSI_tree_1044.root"); 
 	fChain.Add("SamSI_tree_1045.root"); fChain.Add("SamSI_tree_1046.root"); fChain.Add("SamSI_tree_1044.root");
 	fChain.Add("SamSI_tree_1048.root"); fChain.Add("SamSI_tree_1049.root"); fChain.Add("SamSI_tree_1050.root"); 
 	fChain.Add("SamSI_tree_1051.root"); fChain.Add("SamSI_tree_1052.root"); fChain.Add("SamSI_tree_1053.root"); 
 	fChain.Add("SamSI_tree_1054.root"); fChain.Add("SamSI_tree_1055.root"); fChain.Add("SamSI_tree_1056.root"); 
 	fChain.Add("SamSI_tree_1057.root"); fChain.Add("SamSI_tree_1058.root"); fChain.Add("SamSI_tree_1059.root");
 	fChain.Add("SamSI_tree_1060.root"); fChain.Add("SamSI_tree_1061.root"); fChain.Add("SamSI_tree_1062.root"); 
 	fChain.Add("SamSI_tree_1063.root"); fChain.Add("SamSI_tree_1064.root"); fChain.Add("SamSI_tree_1065.root"); 

 	fChain.Add("SamSI_tree_1066.root"); fChain.Add("SamSI_tree_1067.root"); fChain.Add("SamSI_tree_1068.root"); 
 	fChain.Add("SamSI_tree_1069.root"); fChain.Add("SamSI_tree_1070.root"); fChain.Add("SamSI_tree_1071.root");
 	fChain.Add("SamSI_tree_1072.root"); fChain.Add("SamSI_tree_1073.root"); fChain.Add("SamSI_tree_1074.root");
 	fChain.Add("SamSI_tree_1075.root"); fChain.Add("SamSI_tree_1076.root"); fChain.Add("SamSI_tree_1077.root"); 
 	fChain.Add("SamSI_tree_1078.root"); fChain.Add("SamSI_tree_1079.root"); fChain.Add("SamSI_tree_1080.root"); 
 	fChain.Add("SamSI_tree_1081.root"); fChain.Add("SamSI_tree_1082.root"); fChain.Add("SamSI_tree_1083.root");
 	fChain.Add("SamSI_tree_1084.root"); fChain.Add("SamSI_tree_1085.root"); fChain.Add("SamSI_tree_1086.root"); 
 	fChain.Add("SamSI_tree_1087.root"); fChain.Add("SamSI_tree_1088.root"); fChain.Add("SamSI_tree_1089.root");
 	fChain.Add("SamSI_tree_1090.root"); fChain.Add("SamSI_tree_1091.root"); fChain.Add("SamSI_tree_1092.root");
 	fChain.Add("SamSI_tree_1093.root"); fChain.Add("SamSI_tree_1094.root"); fChain.Add("SamSI_tree_1095.root"); 
 	fChain.Add("SamSI_tree_1096.root"); fChain.Add("SamSI_tree_1097.root"); fChain.Add("SamSI_tree_1098.root");
	
 	fChain.Add("SamSI_tree_1099.root"); fChain.Add("SamSI_tree_1100.root"); fChain.Add("SamSI_tree_1101.root");
 	fChain.Add("SamSI_tree_1102.root"); fChain.Add("SamSI_tree_1103.root"); fChain.Add("SamSI_tree_1104.root");
 	fChain.Add("SamSI_tree_1105.root"); fChain.Add("SamSI_tree_1106.root"); fChain.Add("SamSI_tree_1107.root");
 	fChain.Add("SamSI_tree_1108.root"); fChain.Add("SamSI_tree_1109.root"); fChain.Add("SamSI_tree_1110.root");
 	fChain.Add("SamSI_tree_1111.root"); fChain.Add("SamSI_tree_1112.root"); fChain.Add("SamSI_tree_1113.root"); 
 	fChain.Add("SamSI_tree_1114.root"); fChain.Add("SamSI_tree_1115.root"); fChain.Add("SamSI_tree_1116.root"); 
 	fChain.Add("SamSI_tree_1117.root"); fChain.Add("SamSI_tree_1118.root"); fChain.Add("SamSI_tree_1119.root");
 	fChain.Add("SamSI_tree_1120.root"); fChain.Add("SamSI_tree_1121.root"); fChain.Add("SamSI_tree_1122.root");
 	fChain.Add("SamSI_tree_1123.root"); fChain.Add("SamSI_tree_1124.root"); fChain.Add("SamSI_tree_1125.root");
 	fChain.Add("SamSI_tree_1126.root"); fChain.Add("SamSI_tree_1127.root"); fChain.Add("SamSI_tree_1128.root");
 	fChain.Add("SamSI_tree_1129.root"); fChain.Add("SamSI_tree_1130.root"); fChain.Add("SamSI_tree_1131.root");

 	fChain.Add("SamSI_tree_1132.root"); fChain.Add("SamSI_tree_1133.root"); fChain.Add("SamSI_tree_1134.root");
 	fChain.Add("SamSI_tree_1135.root"); fChain.Add("SamSI_tree_1136.root"); fChain.Add("SamSI_tree_1137.root");
 	fChain.Add("SamSI_tree_1138.root"); fChain.Add("SamSI_tree_1139.root"); fChain.Add("SamSI_tree_1140.root");
 	fChain.Add("SamSI_tree_1141.root"); fChain.Add("SamSI_tree_1142.root"); fChain.Add("SamSI_tree_1143.root");
 	fChain.Add("SamSI_tree_1144.root"); fChain.Add("SamSI_tree_1145.root"); fChain.Add("SamSI_tree_1146.root");
 	fChain.Add("SamSI_tree_1147.root"); fChain.Add("SamSI_tree_1148.root"); fChain.Add("SamSI_tree_1149.root");
 	fChain.Add("SamSI_tree_1150.root"); fChain.Add("SamSI_tree_1151.root"); 
	
///////////////////////////////***********************************/////////////////////////////////////////////////
      /*TChain fChain("SamAgSI"); //samp.geom
      
      fChain.Add("SamAgSI_tree_1000.root"); fChain.Add("SamAgSI_tree_1001.root");  // */

      /*TChain fChain("Sam1"); //samp.geom
      
      fChain.Add("Sam1_tree_1000.root"); fChain.Add("Sam1_tree_1001.root");  // */

      /*TChain fChain("Sam2"); //samp.geom
      
      fChain.Add("Sam2_tree_1000.root"); fChain.Add("Sam2_tree_1001.root");// */
      
      /*TChain fChain("Sam3"); //samp.geom
      
      fChain.Add("Sam3_tree_1000.root"); fChain.Add("Sam3_tree_1001.root");// */

      /*TChain fChain("Sam4"); //samp4.geom
      
      fChain.Add("Sam4_tree_1000.root"); fChain.Add("Sam4_tree_1001.root"); // */
////////////////////////////////*****************************************/////////////////////////////////////////////////

            
     // if (!t) { delete f_gamos; continue; } // just a precaution

	//chain.Print();
// definition of variables	
	Int_t n_entries=0, EventID=0;
	Double_t EventAEnerDep=0.0, EventAEnerLost=0.0, EventInitKinEn;
	
	std::vector<int> *StepNumber=0;
 	std::vector<int> *StepEventID = 0;
	std::vector<double> *StepFinKinEn=0;
	std::vector<double> *StepInKinEn=0;
	std::vector<double>  *StepAcEnDep=0;
   	std::vector<double>  *StepAcEnLost=0;

   	std::vector<double>  *StepFinPosX=0;
   	std::vector<double>  *StepFinPosY=0;
   	std::vector<double>  *StepFinPosZ=0;
	std::vector<string> *StepFinLogVol;//=0;
	std::vector<string> *StepInitLogVol;//=0;   
	std::vector<string> *StepParticle;

// carry out the same variables defined	

  fChain.SetBranchAddress("Event_EventID",&EventID);
  fChain.SetBranchAddress("Event_AccumulatedEnergyDeposited",&EventAEnerDep);
  fChain.SetBranchAddress("Event_AccumulatedEnergyLost",&EventAEnerLost);
  fChain.SetBranchAddress("Event_InitialKineticEnergy",&EventInitKinEn);
  
  fChain.SetBranchAddress("Step_StepNumber", &StepNumber);
  fChain.SetBranchAddress("Step_EventID",&StepEventID);
  fChain.SetBranchAddress("Step_AccumulatedEnergyDeposited",&StepAcEnDep);
  fChain.SetBranchAddress("Step_AccumulatedEnergyLost",&StepAcEnLost);
  fChain.SetBranchAddress("Step_Particle",&StepParticle);

  fChain.SetBranchAddress("Step_FinalKineticEnergy",&StepFinKinEn);
  fChain.SetBranchAddress("Step_InitialKineticEnergy",&StepInKinEn);
  fChain.SetBranchAddress("Step_FinalLogicalVolume", &StepFinLogVol);
  fChain.SetBranchAddress("Step_InitialLogicalVolume", &StepInitLogVol);
  fChain.SetBranchAddress("Step_FinalPosX", &StepFinPosX);
  fChain.SetBranchAddress("Step_FinalPosY", &StepFinPosY);
  fChain.SetBranchAddress("Step_FinalPosZ", &StepFinPosZ);

 
///////////////// fill histogram and load tree

  int nbins = 200;
  gStyle->SetOptStat(1111111);
  TCanvas * c1 = new TCanvas("c1", "c1", 800, 600);
  TH1F *sumS = new TH1F("sumS", "sumS", nbins, 0., 0.0455); // event->Samp2 (samp1.in) 0.05  0., -1.5, 1.5,
  //TH1F *sumS1 = new TH1F("sumS1", "sumS1", nbins, 0., 0.0455); // event1-> Samp1 (samp.in) 0.025

  

	Long64_t nb = 0, nbytes = 0;
	n_entries=fChain.GetEntries();
	for (Int_t j=0; j<n_entries;j++){ //run in all tree //////fecha linha 160
		
    		nb = fChain.GetEntry(j); nbytes += nb;

                //cout<<"file= "<<i<<endl;
		cout<<"entries vector = "<<n_entries<<endl;
		//cout<<"entries vector 1 = "<<fChain.GetEntriesFast()<<endl;
		//cout<<"nbytes = "<<nbytes<<endl;
		//cout<<""<<
		cout<<"Entry = "<<j<<endl;
		//cout<<"size = "<<StepFinLogVol->size()-1<<endl;

		//cout<<"EventID = "<<EventID<<endl;
		
//		cout<<"EventAEnerDep = "<<EventAEnerDep<<endl;
//	        cout<<"EventAEnerLost = "<<EventAEnerLost<<endl;
//		cout<<"StepEventID = "<<StepEventID->size()<<endl;
//		cout<<"StepFinKinEn = "<<StepFinKinEn->size()<<endl;

		//cout<<"Value Vol(before) = "<<StepFinLogVol->at(i)<<endl;

		if(StepFinLogVol->size()!=0){ //load the branches of the tree ///fecha linha 158
			Int_t contador=0;
			cout<<endl;

			while (StepFinLogVol->at(contador) !="control" && contador < StepFinLogVol->size()-1){ /// fecha linha 137
				contador++;

			      	//hist ->Fill(StepFinKinEn->at(contador)); 
	    			/*cout<<"entry vector = "<<contador<<endl;
				cout<<"volume = "<<StepFinLogVol->at(contador)<<endl;
		      		//hist ->Fill(StepFinKinEn->at(contador)); 
				cout<<"StepInKinEn = "<<StepInKinEn->at(contador)<<endl;

				cout<<"StepFinKinEn = "<<StepFinKinEn->at(contador)<<endl;
				cout<<endl;
				cout<<"#####"<<endl;

				cout<<"EnLost by Step = "<<StepInKinEn->at(contador)-StepFinKinEn->at(contador)<<endl;
				
				cout<<"StepAcEnLost = "<<StepAcEnLost->at(contador)<<endl;*/

			}

			Double_t sum=0;
			if (StepFinLogVol->at(contador) !="control") { // fecha linha 148
				
				for(Int_t l=0;l<StepNumber->size();l++){ /// fecha linha 144
					sum = sum + StepAcEnLost->at(l);
				} 
				//sumS -> Fill(sum); //enter in control
				//hist -> Fill(StepAcEnLost->at(contador));
				//event -> Fill(EventAEnerLost); //deu certo!! 
			}

			if (StepFinLogVol->at(contador) =="control") {//linha 154
				mm++; 
				for(Int_t l=0;l<StepNumber->size();l++){ /// fecha linha 144
					sum1 = sum1 + StepAcEnLost->at(l);
				} 
				sumS -> Fill(sum1);
			} 
			
			cout<<endl;
                             
		}
            
	}
cout<< "numero de partículas no controlo =  "<< mm<<endl;
cout<< "ener =  "<< sum1<<endl;

sumS -> SetNameTitle("energy", "Sum of Step Energy Lost for 0.05mm Ti;EKin;Counts"); //Kinetic Energy Energy Lost
sumS -> SetFillColor(0); 
sumS -> Draw("HIST");

TFile *s = new TFile("sumStepAgSI.root", "RECREATE"); // Sam 0.05mm 1.2e5
//TFile *s1 = new TFile("sumStep1.root", "RECREATE"); // Sam 0.025mm
//TFile *s2 = new TFile("sumStep2.root", "RECREATE"); // Sam 0.01mm
//TFile *s3 = new TFile("sumStep3.root", "RECREATE"); // Sam 0.0075mm
//TFile *s4 = new TFile("sumStep4.root", "RECREATE"); // Sam 0.005mm



sumS->Write();

}

But when a run the graphic was empty, what is strange given by the value sum1 return a value different from zero.

Could anyone help me

Attached is the output.png (ener is the value of sum1) and the graphic.png (showing the empty histogram using the variable sum1 to generated it).

graphic_sumStep|690x495

Best regards!

At least:

	std::vector<std::string> *StepFinLogVol = 0;
	std::vector<std::string> *StepInitLogVol = 0;   
	std::vector<std::string> *StepParticle = 0;

And then try with:

  gROOT->cd(); // make sure we're in the "Memory Directory"
  TH1F *sumS = new TH1F("sumS", "sumS", nbins, 0., 0.); // automatic bins
				// ...
				sumS->Fill(sum1); sum1 = 0.;

Ah yeah, I was forgot to upload the others files that may be acess in this link:
https://drive.google.com/drive/folders/1cLOu_jb4LQQee2uhNMfk0KzgZ8r1Btas?usp=sharing

Cheers

Thanks @Wile_E_Coyote!

But the graphic continues the same, without any point .

Best regards

Can you post a simpler version of your macro based on the two root files you posted ?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.