Fatal error: TLegend.h: No such file or directory #include "TLegend.h"

Hi,
When I try to run my script in root I get this error message:
fatal error: TLegend.h: No such file or directory #include “TLegend.h”
Can someone help me?

This is my code:

#include <iostream>
using namespace std;
#include <fstream>
#include <sstream>
#include "stdio.h"
#include <string>
#include <iomanip>
#include "TLegend.h"
#include "TCanvas.h"
#include "TPad.h"
#include "TTree.h"
#include "TH1D.h"
#include "TLegend.h"
#include "TFile.h"
#include "TStyle.h"
#include "TRandom3.h"
#include "TDatime.h"
#include "TLine.h"
#include "TSystem.h"
#include "TString.h"
#include <TUUID.h>
#include "TLegend.h"
#include "TPaveStats.h"
#include "TFile.h"
#include "TF1.h"
#include "TFitResult.h"
#include "TLatex.h"
#include "TMath.h"
#include "TStopwatch.h"
#include "THStack.h"

#define TWOTHIRTYONE 2147483648 // 2^31
#define ROIS 4
#define MAXRONLINES 1000000
#define nentriesMAX 1000000

void MakeTree(
	TString folder = "..",
	TString listModePrefix= "MC2_019",
	TString prefixPath = "",
	double maxtime = 864000.,
	double mintime = 0.    
	)
{
	TString prefix = prefixPath + folder + "/";
    TString input = prefix + listModePrefix;
	double time, energy;
	double lastTime = 0, totalTime = 0;
	TString caenFileName = input + "_ch000.txt";
	cout << caenFileName << endl;
	TH1D* histo_raw = new TH1D("histo_raw", "Raw HPGe; Channels;Counts",
						16384, 0, 16384);
	char Line[200];
	FILE* tempFile = fopen(caenFileName, "r");
	//get rid of header
	for (int i = 0; i < 4; i++) {
		fgets(Line, 200, tempFile);
	}
	while (fgets(Line, 200, tempFile)) {
		stringstream data;
		data << Line;
		data >> time >> energy;
		if (time - lastTime < 0) {
			totalTime += lastTime;
			//cout << "2^32s reached" << endl;
		}
		lastTime = time;
		if (energy > 0 && energy < 16384)
			histo_raw->Fill(energy);
	}
	totalTime += lastTime;
	fclose(tempFile);
	caenFileName = input + "_ch002.txt";
	cout << caenFileName << endl;
	fopen(caenFileName,"r");
	double current;
	double totalCurrent = 0;
	while (fgets(Line, 200, tempFile)) {
		stringstream data;
		data << Line;
		data >> time >> current;
		if (current > 0)
			totalCurrent += current;
	}
	fclose(tempFile);
	cout << "collected charge during this run was: " << totalCurrent*1.E-8/1.E-6 << " uC" << endl;
	cout << "mean current during this run was: " << totalCurrent/totalTime/5.E8/1.E-8/1.E-6 << " uA" << endl;
	cout << "runtime was " << totalTime/2.5E8/2. << " seconds" << endl;
	TCanvas *c1 = new TCanvas("Raw_spectra","Raw specta, ",200,110,1200,700);
	histo_raw->Draw();	
}

Thank you.


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


I cannot run your macro. Some data files are missing.

Please note that you’re including some headers twice, e.g., TLegend and TFile.

Here is data file: Run026_ch002.txt (1.5 MB)

That des not help.

You macro trie to opne:

root [0] 
Processing MakeTree.C...
../MC2_019_ch000.txt

Oh, sorry. You need these two files:

(Attachment Run026_ch000.txt is missing)

Run026_ch002.txt (1.54 MB)

Second file is to big to be uploaded…How could I send it?

Simple question - which ROOT version you are using?

I use root v. 6.04.18.

Can you try with more recent ROOT version?
Also try to put using namespace std after all other ROOT includes.
In some situations it could have side effects if defined before.

Regards,
Sergey

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