I am having trouble running a macro that contains code for a histogram that contains data from a root file. I worked with a friend to created the code contained in the macro and the code was done on a Mac then emailed to me to run on windows. When I try to run the macro as .x test.c I am given the following error message.
Function test() is not defined in current scope C:\Users\trent\Desktop\Research\test.c(45)
I found a similar article on this forum and it had mentioned that you must not have your code began like
int main()
{ void test{
}
I found that this did not apply to my situation. I then found another article stating that you must run the macro as .L test.C or .L test.C+. When I try to do this I am presented with the following message.
Warning: template pair duplicate definition C:\root_v5.34.36/cint\cint\stl_pair.h(31)
Warning: template reverse_iterator duplicate definition C:\root_v5.34.36/cint\cint\stl_iterator.h(269)
Warning: template allocator duplicate definition C:\root_v5.34.36/cint\cint\stl\defalloc.h(134)
Warning: template vector duplicate definition C:\root_v5.34.36/cint\cint\stl_vector.h(44)
Then taken to another root line. I am unsure what is going on and I really need some help! This is my code BTW.
#include <iostream>
#include "TComplex.h"
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include "TMath.h"
#include <math.h>
#include "TChain.h"
#include "TFile.h"
#include "TKey.h"
#include "TObject.h"
#include "TObjString.h"
#include "TTree.h"
#include "TH1F.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TH3D.h"
#include "TProfile.h"
#include "TCanvas.h"
#include "TBits.h"
#include "TRefArray.h"
#include "TStopwatch.h"
#include "TAxis.h"
#include "TRandom.h"
#include "TList.h"
#include "TComplex.h"
#include "TLegend.h"
#include "TMath.h"
#include "TLatex.h"
#include "TStyle.h"
#include "TMultiGraph.h"
#include "TGraphErrors.h"
#include "TGraphAsymmErrors.h"
#include "TTree.h"
#include "TH1F.h"
#include <fstream>
using namespace std;
void test () {
TFile *file = TFile::Open("\Users\trent\Desktop\mcglauber7ca_A208_sgm64.0.root");
TTree *tree = (TTree*) file->Get("nt;1");
float v2;
tree->SetBranchAddress("v2", &v2);
cout << v2 <<endl;
TH1F *hist = new TH1F("hist","hist",1000,0,0.3);
int nentries = tree->GetEntries();
cout << nentries <<endl;
for (int i = 1; i <nentries ; i++) {
tree->GetEntry(i);
if(i%1000==0) cout << v2 <<endl;
hist->Fill(v2);
}
hist->Draw();
return 0;
}