Hello guys,
Here I have a code, I wanna create a histogram but I can’t. What’s the matter?
Tips for Efficient and Successful Posting
[Badom.root (1.7 MB)
#include <array>
#include <string>
#include <vector>
#include <math.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include "TApplication.h"
#include "TNtuple.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TH1D.h"
#include "TFile.h"
#include "TLeaf.h"
using namespace std;
void ReadFromNTTree(){
const int NRSamples = 249900;
const int NrNSamplesPerEvent = 4998;
const int NREvents = NRSamples / NrNSamplesPerEvent;
int Index = 0;
const int Baseline_Sample = 50;
int threshold = 1;
int timestamp = 0;
int Gate = 4500;
int Pregate = 2;
int num = 0;
int Num = 0;
int NUM = 0;
double t = 1;
double T = 0.05;
double Q1 = 0.0;
double Q2 = 0.0;
double Q = 0.0;
double FinalData[NREvents][NrNSamplesPerEvent];
TFile* MyFile = new TFile("Badom.root");
TTree* TREE = (TTree*)MyFile->Get("MY TREE");
double Fdata = 0;
TREE->SetBranchAddress("FDATA", &Fdata);
TCanvas *Canvas = new TCanvas("Canvas", "Histogram");
TH1D *EventHisto1 = new TH1D("EventHisto1", "F Histogram", 10.0, 0.0, 750.0);
cout << "Analyzing file ... " << endl << '\n';
Long64_t NEntries = TREE->GetEntries();
Long64_t EVENT_it = 0, SAMPLE_it = 0;
cout << "NrEntries: " << NEntries << endl;
int num = 0;
for (Long64_t j = 0; j < NEntries; j++) {
Index++;
TREE->GetEntry(j);
FinalData[EVENT_it][SAMPLE_it] = Fdata;
SAMPLE_it += 1;
//cout <<"Event is : "<<'\t'<< EVENT_it <<'\t'<<"sample is : "<<'\t'<< SAMPLE_it <<'\t'<<"data is:"<<'\t'<< Fdata << endl;
if (Index == NrNSamplesPerEvent) {
Index = 0;
EVENT_it += 1; SAMPLE_it = 0;
cout << "****************** Event Nr is: " << EVENT_it << "*********************" << endl;
for (int sam1 = 0; sam1 < NrNSamplesPerEvent; sam1++) {
if (FinalData[EVENT_it-1][sam1]) > threshold) {
timestamp = sam1;
break;
}//if (FinalData[NREvents][NrNSamplesPerEvent][sam1]) > threshold)
}//for (int sam1 = 0; sam1 < NrNSamplesPerEvent; sam1++)
if (timestamp <= Pregate)
Pregate = timestamp;
for (int sam2 = timestamp - Pregate; sam2 < Gate; sam2++) {
Q1 += (FinalData[EVENT_it-1][sam2]) * 2;
Q2 += (FinalData[EVENT_it-1][sam2 + 1]) * 2;
}//for(int sam8=0 ; sam8<NrSamples; sam8++)
num++;
Q = (Q1 + Q2) / 2;
EventHisto1->Fill(Q);
}//if (Index == NrNSamplesPerEvent)
//TGraph *plot = new TGraph("output1.txt");
}//for (Long64_t i = 0; i<nentries; i++)
Canvas->Divide();
Canvas->cd();
EventHisto1->Draw();
Canvas->Update();
}//void ReadFromTTree()