Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 struct chan_info{
0002     int pid;
0003     int module;
0004     int chip;
0005     int chan;
0006     // int entry;
0007 };
0008 
0009 // note : .first=dead channel. .second=hot channel
0010 pair<vector<chan_info>,vector<chan_info>> bad_chan_finder(string folder_direction, string file_name, double hot_ch_cut, int iteration = 2)
0011 {
0012     TFile * file_in = TFile::Open(Form("%s/%s.root",folder_direction.c_str(),file_name.c_str()));
0013     TTree * tree = (TTree *)file_in->Get("tree");
0014     long long N_event = tree -> GetEntries();
0015     cout<<Form("N_event in file %s : %lli",file_name.c_str(), N_event)<<endl;
0016 
0017     vector<chan_info> dead_ch_vec; dead_ch_vec.clear();
0018     vector<chan_info> hot_ch_vec; hot_ch_vec.clear();
0019 
0020     for ( int pid_i = 3001; pid_i < 3009; pid_i++ ) // note : from 3001 to 3008
0021     {
0022         for ( int module_i = 0; module_i < 14; module_i++ ) // note  from 0 to 13
0023         {
0024             // todo : it may be just a test, adc is not used
0025             for ( int chip_i = 1; chip_i < 27; chip_i++ ) // note : chip 1 to chip 26 
0026             {
0027                 TH1F * chan_hist = new TH1F("chan_hist","chan_hist",128,0,128);
0028                 tree->Draw("chan_id>>chan_hist", Form("pid == %i && module == %i && chip_id == %i", pid_i, module_i, chip_i));
0029 
0030                 // note : find the dead channel
0031                 for (int ele_i = 0; ele_i < 128; ele_i++){
0032                     if (chan_hist -> GetBinContent(ele_i + 1) == 0){
0033                         dead_ch_vec.push_back( {pid_i, module_i, chip_i, ele_i} );
0034                     }
0035                 }
0036 
0037                 // note : scan iteration
0038                 // note : find the hot channel
0039                 for ( int ite = 0; ite < iteration; ite++ ){
0040                     TH1F * chan_hist_nor = (TH1F*)chan_hist -> Clone();
0041                     chan_hist_nor -> Scale( 1. / chan_hist_nor -> Integral(-1,-1) );
0042                     
0043                     for (int ele_i = 0; ele_i < 128; ele_i++){
0044                         if (chan_hist_nor -> GetBinContent(ele_i + 1) > hot_ch_cut){
0045                             hot_ch_vec.push_back( {pid_i, module_i, chip_i, ele_i} );
0046                             chan_hist -> SetBinContent(ele_i + 1, 0);
0047                         }
0048                     }
0049 
0050                 } 
0051             } // note : chip
0052         } // note : module 
0053     } // note : pid
0054 
0055     return {dead_ch_vec, hot_ch_vec};
0056     
0057 }
0058 
0059 void hot_dead_chan_finder()
0060 {
0061 
0062 }