Back to home page

sPhenix code displayed by LXR

 
 

    


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 //R__LOAD_LIBRARY(libInttEvent.so)
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   //t_mbd->SetBranchAddress("evt", &evt);
0034   //t_mbd->SetBranchAddress("bns", &bns);
0035   //t_mbd->SetBranchAddress("bnn", &bnn);
0036   //t_mbd->SetBranchAddress("clk", &clk);
0037   //t_mbd->SetBranchAddress("femclk", &femclk);
0038   //t_mbd->SetBranchAddress("bqs", &bqs);
0039   //t_mbd->SetBranchAddress("bqn", &bqn);
0040   //t_mbd->SetBranchAddress("bts", &bts);
0041   //t_mbd->SetBranchAddress("btn", &btn);
0042   //t_mbd->SetBranchAddress("bz",  &bz);
0043   //t_mbd->SetBranchAddress("bt0", &bt0);
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   //cout<<t_mbd->GetEntries()<<endl;
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   // TH2F *intt_mbd_bco = new TH2F("intt_mbd_bco", "INTT - MBD", 100, 0, 10000, 100, -10, 100000);
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     // cout<<evtseq<<endl;
0084     // if(evtseq==0) found_firstevt=true;
0085     // if(!found_firstevt){
0086     //   continue;
0087     // }
0088     // 
0089 
0090     // int mbdevt = evtseq = mbd_evt_offset;
0091     // cout<<"mbd: "<<mbdevt<<endl;
0092     // mbdt.LoadTree(mbdevt);
0093     // mbdt.GetEntry(mbdevt);
0094 
0095 
0096 
0097     t_intt->GetEntry(i+intt_evt_offset);
0098 
0099     // if((i%100)==0){
0100     //   cout<<i<<" mbd: " <<mbdt.evt<<" "<<hex<<mbdt.clk<<" "<<mbdt.femclk<<dec<<" "<<mbdt.bns<<" "<<mbdt.bnn
0101     //       <<" "<<mbdt.bqs<<" "<<mbdt.bqn<<" "<<mbdt.bz<<endl;
0102     //   cout<<"intt: "<<inttEvt->evtSeq<<" "<<hex<<inttEvt->bco<<dec<<" "<<inttEvt->fNhits<<endl;
0103     //   cout<<endl;
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     // if (i == 7012) intt_evt_offset += 1;
0137 
0138     // if(i>200000) break;
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   t->Draw("bz")
0151   t->Draw("bz","abs(bz)<500")
0152   t->Draw("bz>>h(500,-500,500)","abs(bz)<500")
0153   t->Draw("bz>>h(2000,-500,500)","abs(bz)<500")
0154   t->Scan("evt:femclk")
0155   t->Scan("evt:femclk:clk")
0156   tree->Scan("evtSeq:bco&0xFFFF")
0157   .q
0158   TFile *_file0 = TFile::Open("/sphenix/user/chiu/sphenix_bbc/run2023/beam_mbd-00020708-0000_mbd.root")
0159   t->Print()
0160   t->Draw("qs")
0161   t->Draw("bqs:bqn")
0162   t->Draw("bqs:bqn","","colz")
0163   t->Draw("bqs:bqn>>h(200,0,2000,200,0,2000)","","colz")
0164   t->Draw("bqs+bqn:evt>>h(200,0,200,100,0,2000)","evt<200")
0165   tree->Scan("fNhits:evtSeq","evtSeq<100")
0166   tree->Draw("fNhits:evtSeq","evtSeq<100")
0167   .q
0168   TFile *_file0 = TFile::Open("../../../../INTT/INTT/general_codes/hachiya/InttEventSync/beam_inttall-00020708-0000_event_base_ana.root")
0169   tree->Draw("fNhits:evtSeq","evtSeq<100")
0170   tree->SetMarkerStyle(20)
0171   tree->Draw("fNhits:evtSeq","evtSeq<100")
0172   t->Draw("bns+bnn:evt>>h(200,0,200,128,0,128)","evt<200")
0173   t->Draw("bqs+bqn:evt>>h(200,0,200,100,0,2000)","evt<200")
0174   t->Draw("bns+bnn:evt>>h(200,0,200,128,0,128)","evt<200")
0175   t->Draw("bqs+bqn:evt>>h(200,0,200,100,0,2000)","evt<200")
0176   .q
0177   TFile *_file0 = TFile::Open("AnaTutorial.root")
0178   ntp_cluspair->Draw("ang1-ang2:ang1>>h(300,-3,3,400, -0.5, 0.5)","nclus2<200","colz")
0179   .q
0180   TFile *_file0 = TFile::Open("AnaTutorial_run20869_newgeo.root")
0181   ntp_cluspair->Draw("vy:vx>>h(200,-1,1,200, -1, 1","nclus2<200","colz")
0182   ntp_cluspair->Draw("vy:vx>>h(200,-1,1,200, -1, 1","nclus2<200&&abs(ang1)<1.5","colz")
0183   ntp_cluspair->Draw("vy:vx>>h1(200,-1,1,200, -1, 1","nclus2<200&&abs(ang1)>1.5","colz")
0184   ntp_cluspair->Draw("vy:vx>>h(200,-1,1,200, -1, 1","nclus2<200&&abs(ang1)<1.5","colz")
0185   ntp_cluspair->Draw("vy:vx>>h1(200,-1,1,200, -1, 1","nclus2<200&&abs(ang1)>1.5","colz")
0186   ntp_clus->Draw("z")
0187   c1->cd()
0188   ntp_cluspair->Draw("vy:vx>>h(200,-1,1,200, -1, 1","nclus2<200&&abs(ang1)<1.5&&abs(ang1-ang2)<0.1","colz")
0189   c1_n2->cd()
0190   ntp_cluspair->Draw("vy:vx>>h(200,-1,1,200, -1, 1","nclus2<200&&abs(ang1)>1.5&&abs(ang1-ang2)<0.1","colz")
0191   ntp_cluspair->Draw("vy:vx>>h1(200,-1,1,200, -1, 1","nclus2<200&&abs(ang1)>1.5&&abs(ang1-ang2)<0.1","colz")
0192   c1->Cd()
0193   c1->cd()
0194   ntp_cluspair->Draw("vy:vx>>h(200,-1,1,200, -1, 1","nclus2<200&&abs(ang1)<1.5&&abs(ang1-ang2)<0.1","colz")
0195 */
0196 }