Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:11:56

0001 #include "TH2INTT.h"
0002 
0003 struct chan_info{
0004     int pid;
0005     int module;
0006     int chip;
0007     int chan;
0008     int adc;
0009     // int entry;
0010 };
0011 
0012 struct to_ch_str{
0013     int pid;
0014     int module;
0015     int chip;
0016     int chan;
0017 };
0018 
0019 to_ch_str convertToIndices(int input) {
0020     const int dim1 = 8;
0021     const int dim2 = 14;
0022     const int dim3 = 26;
0023     const int dim4 = 128;
0024 
0025     to_ch_str result;
0026     result.chan = input % dim4;
0027     input /= dim4;
0028     result.chip = input % dim3;
0029     input /= dim3;
0030     result.module = input % dim2;
0031     input /= dim2;
0032     result.pid = input % dim1;
0033 
0034     return result;
0035 }
0036 
0037 void print_clone_hit()
0038 {   
0039     
0040     string folder_directory = "/sphenix/user/ChengWei/INTT/INTT_commissioning/ZeroField/20869";
0041     string file_name = "beam_inttall-00020869-0000_event_base_ana";
0042     string output_directory = folder_directory + "/PreCheck_" + file_name;
0043     double standard_ch_ratio_typeA = 1. / (8*14*16*128); // note : typeA, 16 sensor cells
0044     double standard_ch_ratio_typeB = 1. / (8*14*10*128); // note : typeB, 10 sensor cells
0045     int criterion = 3;
0046     bool All_event_used = false;
0047     long long defined_event = 200000; // note : only the in the case that the All_event_used is false
0048 
0049     system(Form("mkdir %s",output_directory.c_str()));
0050 
0051     TFile * file_in = TFile::Open(Form("%s/%s.root",folder_directory.c_str(),file_name.c_str()));
0052     TTree * tree = (TTree *)file_in->Get("tree");
0053     long long N_event = (All_event_used == true) ? tree -> GetEntries() : defined_event; 
0054     cout<<Form("N_event in file %s : %lli",file_name.c_str(), N_event)<<endl;
0055     
0056 
0057     int fNhits;
0058     int pid[100000]; // todo : if the fNhits greater than 100000, it may not work
0059     int module[100000];
0060     int chip_id[100000];
0061     int chan_id[100000];
0062     int adc[100000];
0063     // int bco[100000];
0064     // Long64_t bco_full[100000];
0065 
0066     
0067     tree -> SetBranchStatus("*",0);
0068     tree -> SetBranchStatus("fNhits",1);
0069     tree -> SetBranchStatus("fhitArray.pid",1);
0070     tree -> SetBranchStatus("fhitArray.module",1);
0071     tree -> SetBranchStatus("fhitArray.chip_id",1);
0072     tree -> SetBranchStatus("fhitArray.chan_id",1);
0073     tree -> SetBranchStatus("fhitArray.adc",1);
0074     // tree -> SetBranchStatus("fhitArray.bco",1);
0075     // tree -> SetBranchStatus("fhitArray.bco_full",1);
0076 
0077     tree -> SetBranchAddress("fNhits",&fNhits);
0078     tree -> GetEntry(0); // note : actually I really don't know why this line is necessary.
0079     tree -> SetBranchAddress("fhitArray.pid",&pid[0]);
0080     tree -> SetBranchAddress("fhitArray.module",&module[0]);
0081     tree -> SetBranchAddress("fhitArray.chip_id",&chip_id[0]);
0082     tree -> SetBranchAddress("fhitArray.chan_id",&chan_id[0]);
0083     tree -> SetBranchAddress("fhitArray.adc",&adc[0]);
0084     // tree -> SetBranchAddress("fhitArray.bco",&bco[0]);
0085     // tree -> SetBranchAddress("fhitArray.bco_full",&bco_full[0]);
0086 
0087     // note : ch_hit[pid][module][chip][channel]
0088     int ch_adc[8][14][26][128]; memset(ch_adc, -1, sizeof(ch_adc));                              // note : to keep the channel adc, and find the clone hit (single event)
0089     long long ld_clone_all[8][14]; memset(ld_clone_all, 0, sizeof(ld_clone_all));                      // note : N clone hit in that half-ladder in whole file
0090     long long ld_hit_before_all[8][14]; memset(ld_hit_before_all, 0, sizeof(ld_hit_before_all));       // note : N hit in that half-ladder regardless the clone hit or not
0091     long long ld_hit_after_all[8][14]; memset(ld_hit_after_all, 0, sizeof(ld_hit_after_all));          // note : N hit after the clone-hit removal in the whole file
0092     long long ch_hit_after_all[8][14][26][128]; memset(ch_hit_after_all, 0, sizeof(ch_hit_after_all)); // note : N hit of each channel in this file
0093     long long hit_after_all_typeA = 0; // note : U6 to U13 & U19 to U26 
0094     long long hit_after_all_typeB = 0; // note : U1 to U5 & U14 to U18
0095     vector<long long>ch_hit_after_all_seq; ch_hit_after_all_seq.clear();
0096     vector<chan_info> event_hit_info_vec; event_hit_info_vec.clear();
0097     
0098     // int ch_hit[8][14][26][128]; memset(ch_hit, 0, sizeof(ch_hit));  // note : count how many hit the channels have 
0099     int bad_ch[8][14]; memset(bad_ch, 0, sizeof(bad_ch));
0100 
0101     for (int i = 0; i < N_event; i++)
0102     {
0103         tree -> GetEntry(i);
0104         if (i % 1000 == 0) cout<<"running : "<<i<<endl;
0105 
0106         for (int i1 = 0; i1 < fNhits; i1++)
0107         {
0108             if (pid[i1] > 3000 && pid[i1] < 3009 && module[i1] > -1 && module[i1] < 14 && chip_id[i1] > 0 && chip_id[i1] < 27 && chan_id[i1] > -1 && chan_id[i1] < 128 && adc[i1] > -1 && adc[i1] < 8) {
0109                 
0110                 if (ch_adc[ pid[i1] - 3001 ][ module[i1] ][ chip_id[i1] - 1 ][ chan_id[i1] ] == -1) // note : not clone
0111                 {
0112                     ch_adc[ pid[i1] - 3001 ][ module[i1] ][ chip_id[i1] - 1 ][ chan_id[i1] ] = adc[i1];
0113                 }
0114                 else 
0115                 {
0116                     cout<<"clone hit found, event : "<<i<<" pid : "<<pid[i1]<<" module : "<<module[i1]<<" chip : "<<chip_id[i1]<<" chan : "<<chan_id[i1]<<" adc : "<<adc[i1]<<endl;
0117                     ld_clone_all[ pid[i1] - 3001 ][ module[i1] ] += 1; // note : it's clone hit
0118                     ch_adc[ pid[i1] - 3001 ][ module[i1] ][ chip_id[i1] - 1 ][ chan_id[i1] ] = adc[i1]; //  note : the last one is used
0119                 }
0120                 
0121                 ld_hit_before_all[ pid[i1] - 3001 ][ module[i1] ] += 1; 
0122 
0123             }
0124         }
0125 
0126         for (int i0 = 0; i0 < 8; i0++) // note : pid
0127         {
0128             for (int i1 = 0; i1 < 14; i1++) // note : module
0129             {
0130                 for (int i2 = 0; i2 < 26; i2++) // note : chip - 1
0131                 {
0132                     for (int i3 = 0; i3 < 128; i3++) // note : channel
0133                     {
0134                         if ( ch_adc[i0][i1][i2][i3] != -1 ){
0135                             event_hit_info_vec.push_back({i0, i1, i2+1, i3, ch_adc[i0][i1][i2][i3]});
0136                             ld_hit_after_all[i0][i1] += 1;
0137                             ch_hit_after_all[i0][i1][i2][i3] += 1;
0138                             
0139                             // note : type B
0140                             if ((i2 >= 0 && i2 <= 4) || ( i2 >= 13 && i2 <= 17) ) { hit_after_all_typeB += 1; }
0141                             else { hit_after_all_typeA += 1; } // note : type A                           
0142                         }
0143                         
0144                     }
0145                 }
0146             }
0147         }        
0148 
0149         memset(ch_adc, -1, sizeof(ch_adc));
0150         // memset(ld_clone_all, 0, sizeof(ld_clone_all)); // note : N_clone_hit along all the events.
0151         event_hit_info_vec.clear();
0152         
0153     } // note : for loop, end of event
0154 }