Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:12:20

0001 #include "ReadEvtXY.h"
0002 
0003 
0004 ReadEvtXY::ReadEvtXY(TTree *tree) : fChain(0) 
0005 {
0006 // if parameter tree is not specified (or zero), connect the file
0007 // used to generate this class and read the Tree.
0008    if (tree == 0) {
0009       TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("evt_XY_tree.root");
0010       if (!f || !f->IsOpen()) {
0011          f = new TFile("evt_XY_tree.root");
0012       }
0013       f->GetObject("tree",tree);
0014 
0015    }
0016    Init(tree);
0017 }
0018 
0019 ReadEvtXY::~ReadEvtXY()
0020 {
0021    if (!fChain) return;
0022    delete fChain->GetCurrentFile();
0023 }
0024 
0025 Int_t ReadEvtXY::GetEntry(Long64_t entry)
0026 {
0027 // Read contents of entry.
0028    if (!fChain) return 0;
0029    return fChain->GetEntry(entry);
0030 }
0031 Long64_t ReadEvtXY::LoadTree(Long64_t entry)
0032 {
0033 // Set the environment to read one entry
0034    if (!fChain) return -5;
0035    Long64_t centry = fChain->LoadTree(entry);
0036    if (centry < 0) return centry;
0037    if (fChain->GetTreeNumber() != fCurrent) {
0038       fCurrent = fChain->GetTreeNumber();
0039       Notify();
0040    }
0041    return centry;
0042 }
0043 
0044 void ReadEvtXY::Init(TTree *tree)
0045 {
0046    // The Init() function is called when the selector needs to initialize
0047    // a new tree or chain. Typically here the branch addresses and branch
0048    // pointers of the tree will be set.
0049    // It is normally not necessary to make changes to the generated
0050    // code, but the routine can be extended by the user if needed.
0051    // Init() will be called many times when running on PROOF
0052    // (once per file to be processed).
0053 
0054    // Set object pointer
0055    reco_vtx_x = 0;
0056    reco_vtx_y = 0;
0057    reco_vtx_x_stddev = 0;
0058    reco_vtx_y_stddev = 0;
0059    binwidth_x = 0;
0060    binwidth_y = 0;
0061    // Set branch addresses and branch pointers
0062    if (!tree) return;
0063    fChain = tree;
0064    fCurrent = -1;
0065    fChain->SetMakeClass(1);
0066 
0067    fChain->SetBranchAddress("eID", &eID, &b_eID);
0068    fChain->SetBranchAddress("NClus", &NClus, &b_NClus);
0069    fChain->SetBranchAddress("bco_full", &bco_full, &b_bco_full);
0070    fChain->SetBranchAddress("true_vtx_x", &true_vtx_x, &b_true_vtx_x);
0071    fChain->SetBranchAddress("true_vtx_y", &true_vtx_y, &b_true_vtx_y);
0072    fChain->SetBranchAddress("true_vtx_z", &true_vtx_z, &b_true_vtx_z);
0073    fChain->SetBranchAddress("reco_vtx_x", &reco_vtx_x, &b_reco_vtx_x);
0074    fChain->SetBranchAddress("reco_vtx_y", &reco_vtx_y, &b_reco_vtx_y);
0075    fChain->SetBranchAddress("reco_vtx_z", &reco_vtx_z, &b_reco_vtx_z);
0076    fChain->SetBranchAddress("reco_vtx_z_width", &reco_vtx_z_width, &b_reco_vtx_z_width);
0077    fChain->SetBranchAddress("reco_vtx_x_stddev", &reco_vtx_x_stddev, &b_reco_vtx_x_stddev);
0078    fChain->SetBranchAddress("reco_vtx_y_stddev", &reco_vtx_y_stddev, &b_reco_vtx_y_stddev);
0079    fChain->SetBranchAddress("binwidth_x", &binwidth_x, &b_binwidth_x);
0080    fChain->SetBranchAddress("binwidth_y", &binwidth_y, &b_binwidth_y);
0081    Notify();
0082 }
0083 
0084 Bool_t ReadEvtXY::Notify()
0085 {
0086    // The Notify() function is called when a new file is opened. This
0087    // can be either for a new TTree in a TChain or when when a new TTree
0088    // is started when using PROOF. It is normally not necessary to make changes
0089    // to the generated code, but the routine can be extended by the
0090    // user if needed. The return value is currently not used.
0091 
0092    return kTRUE;
0093 }
0094 
0095 void ReadEvtXY::Show(Long64_t entry)
0096 {
0097 // Print contents of entry.
0098 // If entry is not specified, print current entry
0099    if (!fChain) return;
0100    fChain->Show(entry);
0101 }
0102 Int_t ReadEvtXY::Cut(Long64_t entry)
0103 {
0104 // This function may be called from Loop.
0105 // returns  1 if entry is accepted.
0106 // returns -1 otherwise.
0107    return 1;
0108 }
0109 
0110 void ReadEvtXY::Loop()
0111 {
0112 //   In a ROOT session, you can do:
0113 //      root> .L ReadEvtXY.C
0114 //      root> ReadEvtXY t
0115 //      root> t.GetEntry(12); // Fill t data members with entry number 12
0116 //      root> t.Show();       // Show values of entry 12
0117 //      root> t.Show(16);     // Read and show values of entry 16
0118 //      root> t.Loop();       // Loop on all entries
0119 //
0120 
0121 //     This is the loop skeleton where:
0122 //    jentry is the global entry number in the chain
0123 //    ientry is the entry number in the current Tree
0124 //  Note that the argument to GetEntry must be:
0125 //    jentry for TChain::GetEntry
0126 //    ientry for TTree::GetEntry and TBranch::GetEntry
0127 //
0128 //       To read only selected branches, Insert statements like:
0129 // METHOD1:
0130 //    fChain->SetBranchStatus("*",0);  // disable all branches
0131 //    fChain->SetBranchStatus("branchname",1);  // activate branchname
0132 // METHOD2: replace line
0133 //    fChain->GetEntry(jentry);       //read all branches
0134 //by  b_branchname->GetEntry(ientry); //read only this branch
0135    if (fChain == 0) return;
0136 
0137    Long64_t nentries = fChain->GetEntriesFast();
0138 
0139    Long64_t nbytes = 0, nb = 0;
0140    for (Long64_t jentry=0; jentry<nentries;jentry++) {
0141       Long64_t ientry = LoadTree(jentry);
0142       if (ientry < 0) break;
0143       nb = fChain->GetEntry(jentry);   nbytes += nb;
0144       // if (Cut(ientry) < 0) continue;
0145    }
0146 }