Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:12:45

0001 #include <iostream>
0002 #include <string>
0003 #include "LoadData.h"
0004 
0005 void LoadData(string filename) {
0006   TFile *file = TFile::Open(filename.c_str(),"READ");
0007 
0008   if(!file || file->IsZombie()) {
0009     cout << "Failed to open "<<filename.c_str();
0010     cout <<" QUIT!" <<endl;
0011     exit(0);
0012   }
0013   
0014   // connect to the TTrees in the nDST file
0015   evtTree       = dynamic_cast<TTree*>(file->Get("evtTree"));
0016   caloTree      = dynamic_cast<TTree*>(file->Get("caloTree"));
0017   SiClusTree    = dynamic_cast<TTree*>(file->Get("SiClusTree"));
0018   SiClusAllTree = dynamic_cast<TTree*>(file->Get("SiClusAllTree"));
0019   trackTree     = dynamic_cast<TTree*>(file->Get("trackTree"));
0020   topoTree      = dynamic_cast<TTree*>(file->Get("TopoClusTree"));
0021   truthTree     = dynamic_cast<TTree*>(file->Get("truthTree"));
0022 
0023   if(evtTree == nullptr) {
0024     cout << "There is no evtTree. QUIT"<<endl;
0025     exit(0);
0026   }         
0027   if(truthTree == nullptr) {
0028     cout << "No truth info" <<endl;
0029   }
0030     
0031   //data in evtTree
0032   evtTree->SetBranchAddress("evt",&evt);
0033   evtTree->SetBranchAddress("xgvtx",&xgvtx);
0034   evtTree->SetBranchAddress("ygvtx",&ygvtx);
0035   evtTree->SetBranchAddress("zgvtx",&zgvtx);
0036 
0037   //data in caloTree
0038   caloTree->SetBranchAddress("energy",&energy);
0039   caloTree->SetBranchAddress("phi",&emc_phi);
0040   caloTree->SetBranchAddress("eta",&emc_eta);
0041   caloTree->SetBranchAddress("r",&emc_r);
0042   caloTree->SetBranchAddress("z",&emc_z);
0043   caloTree->SetBranchAddress("Calo_tower_ieta",&emc_tower_ieta);
0044   caloTree->SetBranchAddress("Calo_tower_iphi",&emc_tower_iphi);
0045   caloTree->SetBranchAddress("Calo_tower_e",&emc_tower_e);
0046   caloTree->SetBranchAddress("Calo_tower_x",&emc_tower_x);
0047   caloTree->SetBranchAddress("Calo_tower_y",&emc_tower_y);
0048   caloTree->SetBranchAddress("Calo_tower_z",&emc_tower_z);
0049   caloTree->SetBranchAddress("Calo_tower_r",  &emc_tower_r);
0050   caloTree->SetBranchAddress("Calo_tower_phi",&emc_tower_eta);
0051   caloTree->SetBranchAddress("Calo_tower_eta",&emc_tower_phi);
0052   caloTree->SetBranchAddress("Calo_tower_time",&emc_tower_time);
0053   
0054   //data in topoClusTree
0055   topoTree->SetBranchAddress("clus_e",&top_e);
0056   topoTree->SetBranchAddress("clus_x",&top_x);
0057   topoTree->SetBranchAddress("clus_y",&top_y);
0058   topoTree->SetBranchAddress("clus_z",&top_z);
0059   topoTree->SetBranchAddress("clus_r",&top_r);
0060   topoTree->SetBranchAddress("clus_eta",&top_eta);
0061   topoTree->SetBranchAddress("clus_z",&top_z);
0062   topoTree->SetBranchAddress("clus_phi",&top_phi);
0063   topoTree->SetBranchAddress("clus_emcal_e",&emc_e);
0064   topoTree->SetBranchAddress("clus_ihcal_e",&ihc_e);
0065   topoTree->SetBranchAddress("clus_ohcal_e",&ohc_e);
0066 
0067   //data in SiClusTree
0068   SiClusTree->SetBranchAddress("Siclus_layer",&layer);
0069   SiClusTree->SetBranchAddress("Siclus_trackid",&trkid);
0070   SiClusTree->SetBranchAddress("Siclus_x",&si_x);
0071   SiClusTree->SetBranchAddress("Siclus_y",&si_y);
0072   SiClusTree->SetBranchAddress("Siclus_z",&si_z);
0073 
0074   //data in SiClusAllTree
0075   SiClusAllTree->SetBranchAddress("Siclus_layer",&a_layer);
0076   //  SiClusAllTree->SetBranchAddress("Siclus_trackid",&a_trkid);
0077   SiClusAllTree->SetBranchAddress("Siclus_x",&a_si_x);
0078   SiClusAllTree->SetBranchAddress("Siclus_y",&a_si_y);
0079   SiClusAllTree->SetBranchAddress("Siclus_z",&a_si_z);
0080   SiClusAllTree->SetBranchAddress("Siclus_t",&a_si_t);
0081   
0082   //data in trackTree
0083   trackTree->SetBranchAddress("eta0",&eta0);
0084   trackTree->SetBranchAddress("phi0",&phi0);
0085   trackTree->SetBranchAddress("pt0",&pt0);
0086   trackTree->SetBranchAddress("x0",&vx0);
0087   trackTree->SetBranchAddress("y0",&vy0);
0088   trackTree->SetBranchAddress("z0",&vz0);
0089 
0090   //Simulaiton: data in truthTree
0091   if(truthTree != nullptr) {
0092     cout << "This is simulation. Load truth data"<<endl;
0093     truthTree->SetBranchAddress("truth_pid",&truth_pid);
0094     truthTree->SetBranchAddress("truth_px",&truth_px);
0095     truthTree->SetBranchAddress("truth_py",&truth_py);
0096     truthTree->SetBranchAddress("truth_pz",&truth_pz);
0097     truthTree->SetBranchAddress("truth_e",&truth_e);
0098     truthTree->SetBranchAddress("truth_x",&truth_x);
0099     truthTree->SetBranchAddress("truth_y",&truth_y);
0100     truthTree->SetBranchAddress("truth_z",&truth_z);
0101     truthTree->SetBranchAddress("truth_vtx_x",&truth_vtx_x);
0102     truthTree->SetBranchAddress("truth_vtx_y",&truth_vtx_y);
0103     truthTree->SetBranchAddress("truth_vtx_z",&truth_vtx_z);
0104   }
0105 
0106   // Set Beam center
0107   // For run53876
0108   xBC=-0.018;
0109   yBC=0.126;
0110   // For simulaiton data
0111   if(truthTree !=nullptr) {
0112     xBC = 0.0;
0113     yBC = 0.0;
0114   }
0115   cout << "Beam Center (xBC,yBC) = ("<<xBC<<","<<yBC<<")"<<endl;
0116 }
0117 
0118 void GetEvent(int i) {
0119   evtTree->GetEntry(i);
0120   caloTree->GetEntry(i);
0121   trackTree->GetEntry(i);
0122   SiClusTree->GetEntry(i);
0123   SiClusAllTree->GetEntry(i);
0124   topoTree->GetEntry(i);
0125 
0126   if(truthTree != nullptr) {
0127     //this is simulaiton
0128     truthTree->GetEntry(i);
0129   }
0130 }
0131