_ROOT Version:6.12/06
_Platform:Linux Mint 19.2
Compiler: Not Provided
Hello,
So i need to create a histogram from a TTree in a .root file, i used MakeClass() to create a skeleton and everything i have been able to find shows a really simple process to filling your histogram and drawing it, however when i try it i get only 17 endries drawn, which is the number of entries but not the number of instances that are actually included in the branch that i want to draw. I have attempted a second for loop in the .C file that did get the instances, but every entry has a different number of instances and i have not been able to make it break when the entry is read, so it just goes to the next entry, duplicating values in the process. I will include a block with the .C generated code and the definitions from the .h file, sadly because i am a new user i can not upload the root file that i need to access, but i hope that this will be enough.
#define lots_cxx
#include "lots.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
using namespace std;
void lots::Loop()
{
// In a ROOT session, you can do:
// root> .L lots.C
// root> lots t
// root> t.GetEntry(12); // Fill t data members with entry number 12
// root> t.Show(); // Show values of entry 12
// root> t.Show(16); // Read and show values of entry 16
// root> t.Loop(); // Loop on all entries
//
// This is the loop skeleton where:
// jentry is the global entry number in the chain
// ientry is the entry number in the current Tree
// Note that the argument to GetEntry must be:
// jentry for TChain::GetEntry
// ientry for TTree::GetEntry and TBranch::GetEntry
//
// To read only selected branches, Insert statements like:
// METHOD1:
// fChain->SetBranchStatus("*",0); // disable all branches
// fChain->SetBranchStatus("branchname",1); // activate branchname
// METHOD2: replace line
// fChain->GetEntry(jentry); //read all branches
//by b_branchname->GetEntry(ientry); //read only this branch
if (fChain == 0) return;
TH1F *hist1 = new TH1F("hist1", "title", 165, -80, 85);
Long64_t nentries = fChain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;
for (Long64_t jentry=0; jentry<nentries;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
// if (Cut(ientry) < 0) continue;
//for(Long64_t i=0; i<137; i++){
//if (FgdHit_fX[i]==0) break;
//cout<<i<<"="<<FgdHit_fX[i]<<endl;
hist1->Fill(FgdHit_fX[kMaxcbmout_EsbFgdDetector_FgdHit]);
//}
}
hist1->Draw();
//////////////////////////////////////////////////////////
// This class has been automatically generated on
// Sat Apr 27 16:10:40 2024 by ROOT version 6.12/06
// from TTree cbmsim//cbmout
// found on file: fgd_dig.root
//////////////////////////////////////////////////////////
#ifndef lots_h
#define lots_h
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
// Header file for the classes stored in the TTree if any.
#include "FairEventHeader.h"
#include "TClonesArray.h"
#include "TObject.h"
#include "FairMultiLinkedData_Interface.h"
#include "FairTimeStamp.h"
#include "FairHit.h"
#include "EsbData/EsbSuperFGD/FgdHit.h"
class lots {
public :
TTree *fChain; //!pointer to the analyzed TTree or TChain
Int_t fCurrent; //!current Tree number in a TChain
// Fixed size dimensions of array or collections stored in the TTree if any.
static constexpr Int_t kMaxcbmout_EvtHeader_EventHeader = 1;
static constexpr Int_t kMaxcbmout_EsbFgdDetector_FgdHit = 137;
// Declaration of leaf types
FairEventHeader *EventHeader_;
Int_t FgdHit_;
UInt_t FgdHit_fUniqueID[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
UInt_t FgdHit_fBits[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Double_t FgdHit_fTimeStamp[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Double_t FgdHit_fTimeStampError[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Double32_t FgdHit_fDx[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Double32_t FgdHit_fDy[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Double32_t FgdHit_fDz[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Int_t FgdHit_fRefIndex[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Int_t FgdHit_fDetectorID[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Double32_t FgdHit_fX[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Double32_t FgdHit_fY[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Double32_t FgdHit_fZ[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
TVector3 FgdHit_fmppcLoc[kMaxcbmout_EsbFgdDetector_FgdHit];
TVector3 FgdHit_fphotoE[kMaxcbmout_EsbFgdDetector_FgdHit];
TVector3 FgdHit_fdpos[kMaxcbmout_EsbFgdDetector_FgdHit];
Double_t FgdHit_ftime[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
TVector3 FgdHit_fmom[kMaxcbmout_EsbFgdDetector_FgdHit];
TVector3 FgdHit_fmomExit[kMaxcbmout_EsbFgdDetector_FgdHit];
Double_t FgdHit_ftrackLength[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Double_t FgdHit_ftrackLengthOrigin[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
TVector3 FgdHit_fphotoE_dist1[kMaxcbmout_EsbFgdDetector_FgdHit];
TVector3 FgdHit_fmppcLoc_dist1[kMaxcbmout_EsbFgdDetector_FgdHit];
TVector3 FgdHit_fphotoE_dist2[kMaxcbmout_EsbFgdDetector_FgdHit];
TVector3 FgdHit_fmppcLoc_dist2[kMaxcbmout_EsbFgdDetector_FgdHit];
Int_t FgdHit_fpdg[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Int_t FgdHit_ftrackId[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Double_t FgdHit_fedep[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
Double_t FgdHit_fpe[kMaxcbmout_EsbFgdDetector_FgdHit]; //[cbmout.EsbFgdDetector.FgdHit_]
// List of branches
TBranch *b_cbmout_EvtHeader_EventHeader_; //!
TBranch *b_cbmout_EsbFgdDetector_FgdHit_; //!
TBranch *b_FgdHit_fUniqueID; //!
TBranch *b_FgdHit_fBits; //!
TBranch *b_FgdHit_fTimeStamp; //!
TBranch *b_FgdHit_fTimeStampError; //!
TBranch *b_FgdHit_fDx; //!
TBranch *b_FgdHit_fDy; //!
TBranch *b_FgdHit_fDz; //!
TBranch *b_FgdHit_fRefIndex; //!
TBranch *b_FgdHit_fDetectorID; //!
TBranch *b_FgdHit_fX; //!
TBranch *b_FgdHit_fY; //!
TBranch *b_FgdHit_fZ; //!
TBranch *b_FgdHit_fmppcLoc; //!
TBranch *b_FgdHit_fphotoE; //!
TBranch *b_FgdHit_fdpos; //!
TBranch *b_FgdHit_ftime; //!
TBranch *b_FgdHit_fmom; //!
TBranch *b_FgdHit_fmomExit; //!
TBranch *b_FgdHit_ftrackLength; //!
TBranch *b_FgdHit_ftrackLengthOrigin; //!
TBranch *b_FgdHit_fphotoE_dist1; //!
TBranch *b_FgdHit_fmppcLoc_dist1; //!
TBranch *b_FgdHit_fphotoE_dist2; //!
TBranch *b_FgdHit_fmppcLoc_dist2; //!
TBranch *b_FgdHit_fpdg; //!
TBranch *b_FgdHit_ftrackId; //!
TBranch *b_FgdHit_fedep; //!
TBranch *b_FgdHit_fpe; //!
Thank you for the help in advance.
-Boris.