![]() |
|
|||
File indexing completed on 2025-08-06 08:12:30
0001 0002 #include "InttEvent.h" 0003 //#include "InttCluster.h" 0004 //#include "InttEventSync.h" 0005 0006 #include <iostream> 0007 #include <fstream> 0008 #include <map> 0009 #include <vector> 0010 0011 #include <TFile.h> 0012 #include <TTree.h> 0013 #include <TNtuple.h> 0014 #include <TH1.h> 0015 #include <TDirectory.h> 0016 0017 using namespace std; 0018 0019 0020 InttEvent* inttEvt = nullptr; 0021 0022 TFile* outtree_file = nullptr; 0023 0024 TH1F* h_adc; 0025 TH1F* h_adc1; 0026 TH1F* h_adc2; 0027 TH1F* h_nclus; 0028 TH1F* h_nbcofull; 0029 TH1F* h_clussize; 0030 TH1F* h_bcodiff; 0031 TH1F* h_bcodiff2; 0032 TNtuple* h_clustree; 0033 TTree* h_evttree; 0034 0035 TTree* h_mergedtree; 0036 InttEvent* mergedInttEvt=NULL; 0037 0038 0039 // variable for evttree 0040 int pid, evt, nclus[8][14], nhits[8][14]; 0041 uint64_t bco_full; 0042 0043 0044 ////////////////////////////////////////////////// 0045 // 0046 int init_done=0; 0047 0048 int InitAnalysis(const char* outRootfile) 0049 { 0050 if (init_done) return 1; 0051 init_done = 1; 0052 0053 TDirectory* gDir = gDirectory; 0054 0055 /* 0056 outtree_file = TFile::Open(outRootfile, "recreate"); 0057 0058 h_adc = new TH1F("h_adc", "adc", 100, 0, 300); 0059 h_adc1 = new TH1F("h_adc1", "adc1", 100, 0, 300); 0060 h_adc2 = new TH1F("h_adc2", "adc2", 100, 0, 300); 0061 h_nclus = new TH1F("h_nclus", "nclus", 100, 0, 2000); 0062 h_nbcofull = new TH1F("h_nbcofull", "nbcofull", 100, 0, 100); 0063 h_clussize = new TH1F("h_clussize", "cluster size", 100, 0, 100); 0064 h_bcodiff = new TH1F("h_bcodiff", "bcodiff", 1000, -10000000, 10000000); 0065 h_bcodiff2 = new TH1F("h_bcodiff2", "bcodiff2", 1000, -500, 500); 0066 0067 h_clustree = new TNtuple("h_clustree", "cluster tree", "nclus:size:adc:module:chip_id:chan_id:bco_full:roc:barrel:layer:ladder:arm:pid"); 0068 0069 h_evttree = new TTree("h_evttree", "Event tree"); 0070 0071 h_evttree->Branch("pid", &pid, "pid/I"); 0072 h_evttree->Branch("bco_full", &bco_full, "bco_full/l"); 0073 h_evttree->Branch("event", &evt, "event/I"); 0074 h_evttree->Branch("nclus", nclus, "nclus[8][14]/I"); 0075 h_evttree->Branch("nhits", nhits, "nhits[8][14]/I"); 0076 0077 0078 mergedInttEvt = new InttEvent(); 0079 0080 h_mergedtree = new TTree("tree", "Merged InttEvent"); 0081 //h_mergedtree->Branch("event", "InttEvent", &inttEvt, 8000, 99); 0082 h_mergedtree->Branch("event", "InttEvent", &mergedInttEvt, 8000, 99); 0083 */ 0084 0085 0086 gDirectory = gDir; 0087 0088 return 0; 0089 } 0090 0091 int Process_event (InttEvent* inttEvent) 0092 { 0093 0094 /* 0095 InttClusterList* inttClusterList = new InttClusterList; 0096 0097 //Clustering(inttEvent, inttClusterList); 0098 0099 //////////////////////////////////// 0100 // analysis 0101 // 0102 int nHits = inttEvent->getNHits(); 0103 map<Long64_t, int> vbcocount; 0104 for(int ihit = 0; ihit<nHits; ihit++) 0105 { 0106 Long64_t bco_f = inttEvent->getHit(ihit)->bco_full; 0107 auto itrBC = vbcocount.find(bco_f); 0108 if(itrBC==vbcocount.end()){ 0109 vbcocount.insert(make_pair(bco_f, 0)); 0110 } 0111 else { 0112 itrBC->second++; 0113 } 0114 } 0115 //--cout<<"nbco : "<<vbcocount.size()<<endl; 0116 h_nbcofull->Fill(vbcocount.size()); 0117 Long64_t bco_main=0; 0118 int ncount_max=0; 0119 for(auto itrBC = vbcocount.begin(); itrBC!=vbcocount.end(); ++itrBC) 0120 { 0121 if(itrBC->second >= ncount_max) { 0122 ncount_max=itrBC->second; 0123 bco_main = itrBC->first; 0124 } 0125 //--cout<<" "<<itrBC->first<<" "<<itrBC->second<<endl; 0126 } 0127 for(auto itrBC = vbcocount.begin(); itrBC!=vbcocount.end(); ++itrBC) 0128 { 0129 Long64_t bco_diff = itrBC->first - bco_main; 0130 //--cout<<" diff= "<<bco_diff<<endl; 0131 h_bcodiff->Fill(bco_diff, itrBC->second); 0132 h_bcodiff2->Fill(bco_diff, itrBC->second); 0133 } 0134 0135 0136 // hit analysis 0137 for(int ipid=0; ipid<8; ipid++){ 0138 for(int ilad=0; ilad<14; ilad++){ nhits[ipid][ilad]=0;} 0139 } 0140 for(int ihit = 0; ihit<nHits; ihit++) 0141 { 0142 int pid = inttEvent->getHit(ihit)->pid; 0143 int module = inttEvent->getHit(ihit)->module; 0144 0145 if(pid<3001||3008<pid) { cout<<"invalid pid: "<<pid<<endl; continue;} 0146 if(module<0||14<module){ cout<<"invalid module: "<<module<<endl; continue;} 0147 nhits[pid-3001][module]++; 0148 } 0149 0150 0151 ////////////////////////////// 0152 // cluster analysis 0153 int nClusters = inttClusterList->getNhits(); 0154 h_nclus->Fill(nClusters); 0155 0156 //--cout<<"Nclus: "<<nClusters<<endl; 0157 float buf[12]; 0158 for(int ipid=0; ipid<8; ipid++){ 0159 for(int ilad=0; ilad<14; ilad++){ nclus[ipid][ilad]=0;} 0160 } 0161 pid=0; 0162 0163 for(int iclus = 0; iclus<nClusters; iclus++) 0164 { 0165 InttCluster* clus = inttClusterList->getCluster(iclus); 0166 if(clus==nullptr) {cout<<"Null cluster : "<<iclus<<endl; continue; } 0167 0168 h_adc->Fill(clus->adc); 0169 if(clus->nhits==1) h_adc1->Fill(clus->adc); 0170 if(clus->nhits>=2) h_adc2->Fill(clus->adc); 0171 0172 h_clussize->Fill(clus->nhits); 0173 0174 // "nclus:size:adc:module:chip_id:chan_id:bco_full:roc:barrel:layer:ladder:arm:pid"); 0175 buf[ 0] = nClusters; 0176 buf[ 1] = clus->nhits; 0177 buf[ 2] = clus->adc; 0178 buf[ 3] = clus->module; 0179 buf[ 4] = clus->chip_id; 0180 buf[ 5] = clus->ch; 0181 buf[ 6] = clus->bco_full; 0182 buf[ 7] = clus->roc; 0183 buf[ 8] = clus->barrel; 0184 buf[ 9] = clus->layer; 0185 buf[10] = clus->ladder; 0186 buf[11] = clus->arm; 0187 buf[12] = clus->pid; 0188 0189 h_clustree->Fill(buf); 0190 0191 if(iclus==0){ 0192 pid = clus->pid; 0193 bco_full = clus->bco_full; 0194 } 0195 0196 nclus[clus->pid-3001][clus->module]++; 0197 } 0198 // 0199 //////////////////////////////////// 0200 // 0201 h_evttree->Fill(); 0202 0203 mergedInttEvt->clear(); 0204 mergedInttEvt->copy(inttEvent); 0205 h_mergedtree->Fill(); 0206 0207 0208 delete inttClusterList; 0209 */ 0210 0211 return 0; 0212 } 0213 0214 int RunAnalysis(const char *rootFileList) 0215 { 0216 TDirectory* gDir = gDirectory; 0217 0218 cout<<"file : "<<rootFileList<<endl; 0219 0220 //TDirectory* gDir = gDirectory; 0221 TFile *f_intt = TFile::Open("/sphenix/user/hachiya/INTT/INTT/general_codes/hachiya/InttEventSync/beam_inttall-00020708-0000_event_base_ana.root"); 0222 gDirectory = gDir; 0223 TTree *t_intt = (TTree*)f_intt->Get("tree"); 0224 cout<<" "<<t_intt<<endl; 0225 if(!t_intt) return -1; 0226 0227 InttEvent* inttEvt; 0228 t_intt->SetBranchAddress("event", &inttEvt); 0229 0230 /////////// 0231 0232 TFile *f_mbd = TFile::Open("/sphenix/user/chiu/sphenix_bbc/run2023/beam_mbd-00020708-0000_mbd.root"); 0233 0234 //gDirectory = gDir; 0235 TTree *t_mbd = (TTree*)f_mbd->Get("t"); 0236 cout<<" "<<t_mbd<<endl; 0237 if(!t_mbd) return -1; 0238 0239 Int_t evt; 0240 Short_t bns, bnn; 0241 UShort_t clk, femclk; 0242 Float_t bqs, bqn, bts, btn, bz, bt0; 0243 0244 t_mbd->SetBranchAddress("evt", &evt); 0245 t_mbd->SetBranchAddress("bns", &bns); 0246 t_mbd->SetBranchAddress("bnn", &bnn); 0247 t_mbd->SetBranchAddress("clk", &clk); 0248 t_mbd->SetBranchAddress("femclk", &femclk); 0249 t_mbd->SetBranchAddress("bqs", &bqs); 0250 t_mbd->SetBranchAddress("bqn", &bqn); 0251 t_mbd->SetBranchAddress("bts", &bts); 0252 t_mbd->SetBranchAddress("btn", &btn); 0253 t_mbd->SetBranchAddress("bz", &bz); 0254 t_mbd->SetBranchAddress("bt0", &bt0); 0255 0256 /////////////////// 0257 0258 //gDirectory = gDir; 0259 // 0260 cout<<t_intt->GetEntries()<<" "<<t_mbd->GetEntries()<<endl; 0261 0262 bool found_firstevt=false; 0263 int mbd_evt_offset = 2; 0264 for(int i=0; i<t_mbd->GetEntriesFast(); i++){ 0265 t_mbd->GetEntry(i); 0266 t_intt->GetEntry(i); 0267 //-- cout<<"intt: "<<inttEvt->evtSeq<<" "<<hex<<inttEvt->bco<<dec<<" "<<inttEvt->fNhits<<endl; 0268 0269 //-- int evtseq = inttEvt->evtSeq; 0270 //-- cout<<evtseq<<endl; 0271 //-- if(evtseq==0) found_firstevt=true; 0272 //-- if(!found_firstevt){ 0273 //-- continue; 0274 //-- } 0275 //-- 0276 0277 //-- int mbdevt = evtseq = mbd_evt_offset; 0278 //-- cout<<"mbd: "<<mbdevt<<endl; 0279 //t_mbd->LoadEntry(i); 0280 //t_mbd->GetEntry(mbdevt); 0281 0282 cout<<i<<" mbd: " <<evt<<" "<<hex<<clk<<" "<<femclk<<dec<<" "<<bns<<" "<<bnn<<" "<<bqs<<" "<<bqn<<" "<<bz<<endl; 0283 cout<<endl; 0284 0285 if(i>10) break; 0286 } 0287 0288 0289 //ifstream fin(rootFileList); 0290 //if(!fin) { 0291 // cout<<"failed to open file : "<<rootFileList<<endl; 0292 // return -1; 0293 //} 0294 0295 0296 /* 0297 InttEventSync inttEvtSync; 0298 0299 vector<TFile*> vTFile; 0300 char filename[2048]; 0301 int ind=0; 0302 //while(!fin.eof()) 0303 while(fin>>filename) 0304 { 0305 TFile* tree_file = TFile::Open(filename); 0306 vTFile.push_back(tree_file); 0307 gDirectory = gDir; 0308 0309 cout<<ind<<" "<<filename<<" "<<tree_file->GetName()<<endl; 0310 0311 TTree* tree = (TTree*)tree_file->Get("tree"); 0312 inttEvtSync.addData(tree); 0313 0314 0315 ind++; 0316 } 0317 fin.close(); 0318 */ 0319 0320 0321 /* 0322 0323 //read the Tree 0324 int ievt=0; 0325 InttEvent* inttevt = NULL; 0326 while( (inttEvt = inttEvtSync.getNextEvent()) ) 0327 { 0328 if((ievt%10000)==0) cout<<"Event : "<<inttEvt->evtSeq<<endl; 0329 //inttEvt->sort(); 0330 //inttEvt->show(); 0331 0332 Process_event(inttEvt); 0333 0334 0335 delete inttEvt; 0336 inttEvt = NULL; 0337 if(ievt>=100000) { 0338 cout<<"Max event 100000. quit"<<endl; 0339 break; 0340 } 0341 ievt++; 0342 } 0343 0344 0345 //delete hfile; 0346 for(auto fileItr=vTFile.begin(); fileItr!=vTFile.end(); ++fileItr) 0347 { 0348 (*fileItr)->Close(); 0349 } 0350 vTFile.clear(); 0351 0352 h_adc->Print(); 0353 0354 // tree->Write(); 0355 outtree_file->cd(); 0356 outtree_file->Write(); 0357 outtree_file->Close(); 0358 0359 */ 0360 0361 return 0; 0362 } 0363
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |