Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:22

0001 //
0002 // macro to read in MBD data after the waveforms are processed
0003 // at this stage, we only have charge and time from each channel, not the full waveform
0004 //
0005 #include <fstream>
0006 #include <TChain.h>
0007 
0008 #include <mbd/MbdDefs.h>
0009 #include <mbd/MbdOut.h>
0010 #include <mbd/MbdPmtContainer.h>
0011 #include <mbd/MbdPmtHit.h>
0012 
0013 #if defined(__CLING__)
0014 R__LOAD_LIBRARY(libmbd_io.so)
0015 #endif
0016 
0017 // Set up variables to read from TTree
0018 Int_t   f_evt{0};
0019 UShort_t f_clk{0};
0020 UShort_t f_femclk{0};
0021 Short_t  f_npmt;
0022 Float_t f_tt[MbdDefs::MBD_N_PMT];  // time from t-channels
0023 Float_t f_tq[MbdDefs::MBD_N_PMT];  // time from q-channels
0024 Float_t f_q[MbdDefs::MBD_N_PMT];   // charge
0025 
0026 Short_t f_bn[MbdDefs::MBD_N_ARMS]; // num hit PMTs
0027 Float_t f_bq[MbdDefs::MBD_N_ARMS]; // chargesum
0028 Float_t f_bt[MbdDefs::MBD_N_ARMS]; // mean time in arm
0029 Float_t f_bz;                      // z-vertex
0030 Float_t f_bt0;                     // t-zero
0031 
0032 MbdOut *mbdout{nullptr};
0033 MbdPmtContainer *mbdpmts{nullptr};
0034 
0035 TFile *tfile {nullptr};
0036 TTree *tree {nullptr};
0037 
0038 void dstmbd_GetEntry(const int ientry)
0039 {
0040     tree->GetEntry(ientry);
0041 
0042     f_evt = mbdout->get_evt();
0043     f_clk = mbdout->get_clock();
0044     f_femclk = mbdout->get_femclock();
0045     f_bz = mbdout->get_zvtx();
0046     f_bt0 = mbdout->get_t0();
0047     for (int iarm=0; iarm<2; iarm++)
0048     {
0049       f_bn[iarm] = mbdout->get_npmt(iarm);
0050       f_bq[iarm] = mbdout->get_q(iarm);
0051       f_bt[iarm] = mbdout->get_time(iarm);
0052     }
0053     f_npmt = f_bn[0] + f_bn[1];
0054 
0055     // clear pmt info
0056     for (int ipmt=0; ipmt<128; ipmt++)
0057     {
0058       f_q[ipmt] = 0.;
0059       f_tt[ipmt] = NAN;
0060       f_tq[ipmt] = NAN;
0061     }
0062 
0063     // Loop over each MBD/BBC PMT container
0064     for (int ipmt=0; ipmt<mbdpmts->get_npmt(); ipmt++)
0065     {
0066       MbdPmtHit* mbdpmt = mbdpmts->get_pmt(ipmt);
0067 
0068       f_q[ipmt] = mbdpmt->get_q();
0069       f_tt[ipmt] = mbdpmt->get_tt();
0070       f_tq[ipmt] = mbdpmt->get_tq();
0071     }
0072 }
0073 
0074 void read_dstmbd(const char *tfname = "beam_mbd-00009184-0000_mbd.root")
0075 {
0076   cout << "tfname " << tfname << endl;
0077 
0078   // Set up TTree
0079   int is_dst = 0; // whether reading from DST or private root files
0080   tfile = new TFile(tfname,"READ");
0081   tree = (TTree*)tfile->Get("T");
0082 
0083   tree->SetBranchAddress("DST#MBD#MbdOut",&mbdout);
0084   tree->SetBranchAddress("DST#MBD#MbdPmtContainer",&mbdpmts);
0085 
0086   /* older dst style, with better leaf level
0087   tree->SetBranchAddress("EvtSequence",&f_evt);
0088   tree->SetBranchAddress("clk", &f_clk);
0089   tree->SetBranchAddress("femclk", &f_femclk);
0090   tree->SetBranchAddress("bns",&f_bn[0]);
0091   tree->SetBranchAddress("bnn",&f_bn[1]);
0092   tree->SetBranchAddress("bqs",&f_bq[0]);
0093   tree->SetBranchAddress("bqn",&f_bq[1]);
0094   tree->SetBranchAddress("bts",&f_bt[0]);
0095   tree->SetBranchAddress("btn",&f_bt[1]);
0096   tree->SetBranchAddress("bz",&f_bz);
0097   tree->SetBranchAddress("bt0",&f_bt0);
0098   tree->SetBranchAddress("MbdPmtHits.bq",f_q);
0099   tree->SetBranchAddress("MbdPmtHits.btt",f_tt);
0100   tree->SetBranchAddress("MbdPmtHits.btq",f_tq);
0101   */
0102 
0103   // Event loop, each ientry is one triggered event
0104   int nentries = tree->GetEntries();
0105   cout << "checking output of dst file " << tfname << endl;
0106   cout << "nentries = " << nentries << endl;
0107   for (int ientry=0; ientry<10; ientry++)
0108   {
0109     //cout << "ientry " << ientry << endl;
0110     dstmbd_GetEntry(ientry);
0111     //tree->GetEntry(ientry+100);
0112 
0113     if (ientry<10)
0114     {
0115       // print charge from channels 0 and 127
0116       cout << f_evt << "\t" << f_q[0] << "\t" << f_tt[0] << endl;
0117       cout <<  "\t" << f_q[127] << "\t" << f_tt[127] << endl;
0118       cout <<  "\t" << f_bz << endl;
0119     }
0120 
0121   }
0122 
0123 }
0124