File indexing completed on 2025-08-06 08:12:32
0001 #include <TFile.h>
0002 #include <TTree.h>
0003 #include <TDirectory.h>
0004
0005 #include "InttEvent.cc"
0006 #include "mbdtree.C"
0007
0008 #include <iostream>
0009
0010
0011
0012 void sync_mbd_intt()
0013 {
0014 Int_t evt;
0015 Short_t bns, bnn;
0016 UShort_t clk, femclk;
0017 Float_t bqs, bqn, bts, btn, bz, bt0;
0018
0019
0020 TDirectory* gDir = gDirectory;
0021
0022
0023
0024 TFile *f_mbd = TFile::Open("/sphenix/tg/tg01/commissioning/INTT/subsystems/MBD/auau2023_v0/beam_seb18-00020869-0000_mbd.root");
0025 gDirectory=gDir;
0026
0027 TTree *t_mbd = (TTree*)f_mbd->Get("t");
0028 cout<<" "<<t_mbd<<endl;
0029 if(!t_mbd) return ;
0030
0031 mbdtree mbdt(t_mbd);
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 TFile *f_intt = TFile::Open("/sphenix/user/ChengWei/INTT/INTT_commissioning/ZeroField/20869/beam_inttall-00020869-0000_event_base_ana.root");
0047 gDirectory=gDir;
0048 TTree *t_intt = (TTree*)f_intt->Get("tree");
0049 cout<<" "<<t_intt<<endl;
0050 if(!t_intt) return ;
0051
0052 InttEvent* inttEvt;
0053 t_intt->SetBranchAddress("event", &inttEvt);
0054
0055
0056 cout<<t_mbd->GetEntries()<<" "<<t_intt->GetEntries()<<endl;
0057
0058
0059 gDirectory = gDir;
0060
0061 TH2F *h_qmbd_nintt = new TH2F("h_qmbd_nintt", "BbcQ vs Intt N", 200, 0, 20000, 200, 0, 4000);
0062 TH2F *intt_mbd_bco = new TH2F("intt_mbd_bco", "INTT - MBD", 100, 0, 600000, 100, -10, 100000);
0063
0064 intt_mbd_bco->GetXaxis()->SetTitle("evt");
0065 intt_mbd_bco->GetYaxis()->SetTitle("clock_diff");
0066
0067 TH1F *intt_mbd_bco_1D = new TH1F("intt_mbd_bco_1D", "INTT - MBD", 100, -10, 100000);
0068 intt_mbd_bco_1D->GetXaxis()->SetTitle("clock_diff");
0069 intt_mbd_bco_1D->GetYaxis()->SetTitle("entry");
0070
0071 int prev_mbdclk = 0;
0072 ULong64_t prev_bco = 0;
0073
0074 bool found_firstevt=false;
0075 int mbd_evt_offset = 0;
0076 int intt_evt_offset = 0;
0077 for(int i=0; i< t_mbd->GetEntries(); i++){
0078 mbdt.LoadTree(i+mbd_evt_offset);
0079 mbdt.GetEntry(i+mbd_evt_offset);
0080
0081 int INTT_evtseq = inttEvt->evtSeq;
0082 int MBD_evtseq = mbdt.evt;
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 t_intt->GetEntry(i+intt_evt_offset);
0098
0099
0100
0101
0102
0103
0104
0105
0106 float bbcq = mbdt.bqn+mbdt.bqs;
0107 float nintt = inttEvt->fNhits;
0108
0109 unsigned short mbdclk = mbdt.femclk;
0110 ULong64_t bco = inttEvt->bco;
0111 ULong64_t bco16 = bco&0xFFFF;
0112
0113 int mbd_prvdif = (mbdclk-prev_mbdclk)&0xFFFF;
0114 ULong64_t intt_prvdif = bco-prev_bco;
0115
0116 if((i%2000)==0){cout<<i<<" "<<hex<<setw(6)<<mbdclk<<" "<<setw(6)<<bco16<<" (mbd-intt)"<<setw(6)<<((mbdclk-bco16)&0xFFFF)
0117 <<" (femclk-prev)"<<setw(6)<<mbd_prvdif<<" (bco-prev)"<<setw(6)<<intt_prvdif<<dec<<" INTT Evt: "<<INTT_evtseq<<" MBD Evt: "<<MBD_evtseq<<endl;}
0118
0119
0120 if (mbdt.bqs > 200 && mbdt.bqn > 200)
0121 h_qmbd_nintt->Fill(nintt, bbcq);
0122
0123 intt_mbd_bco -> Fill(i,(mbdclk-bco16)&0xFFFF);
0124 intt_mbd_bco_1D -> Fill((mbdclk-bco16)&0xFFFF);
0125
0126 prev_mbdclk = mbdclk;
0127 prev_bco = bco;
0128
0129 t_intt->GetEntry(i+1+intt_evt_offset);
0130 ULong64_t next_bco16 = (inttEvt->bco)&0xFFFF;
0131 mbdt.LoadTree(i+1);
0132 mbdt.GetEntry(i+1);
0133 unsigned short next_mbdclk = mbdt.femclk;
0134 if ( ((next_mbdclk-next_bco16)&0xFFFF) != ((mbdclk-bco16)&0xFFFF)) intt_evt_offset += 1;
0135
0136
0137
0138
0139 }
0140
0141
0142 TFile* froot = new TFile("/sphenix/user/ChengWei/INTT/INTT_commissioning/ZeroField/20869/sync.root", "recreate");
0143 h_qmbd_nintt->Write();
0144 intt_mbd_bco->Write();
0145 intt_mbd_bco_1D->Write();
0146 froot->Close();
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196 }