Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:12:49

0001 #ifndef __INTTCLUSTERING_H_
0002 #define __INTTCLUSTERING_H_
0003 
0004 // #include "InttConversion.h"
0005 
0006 struct clu_info {
0007     int column;
0008     // int chip_id;
0009     double avg_chan;
0010     int sum_adc;
0011     int sum_adc_conv;
0012     int size;
0013 
0014     double x;
0015     double y;
0016     double z;
0017     int layer;
0018     double phi;
0019     // vector<double> bco_diff_vec; // note : for the multi-hit cluster, more than one hit was included. so more than one bco_diff
0020     int raw_layer_id;
0021     int raw_ladder_id;
0022     int raw_Z_id;
0023     int raw_phi_size;
0024     int raw_Z_size;
0025 };
0026 
0027 struct clu_info_private {
0028     int column;
0029     // int chip_id;
0030     double avg_chan;
0031     int sum_adc;
0032     int sum_adc_conv;
0033     int size;
0034 
0035     double x;
0036     double y;
0037     double z;
0038     int layer;
0039     double phi;
0040     vector<double> bco_diff_vec; // note : for the multi-hit cluster, more than one hit was included. so more than one bco_diff
0041 };
0042 
0043 struct hit_info {
0044     int chip_id;
0045     int chan_id;
0046     int adc;
0047     int adc_conv;
0048     int bco_diff; // note : small_bco - bco_full
0049 };
0050 
0051 struct hit_pro_info {
0052     int chip_id;
0053     int chan_id;
0054 
0055     int column_id;
0056     int chan_id_conv;
0057 
0058     int adc;
0059     int adc_conv;
0060 
0061     double x;
0062     double y;
0063     double z;
0064     int layer;
0065     int bco_diff;
0066 };
0067 
0068 namespace InttClustering{
0069     
0070     vector<clu_info_private> clustering(string server_name, int FC_id, vector<hit_info> single_event, InttConversion * ch_pos_DB)
0071     {
0072 
0073         // note : [0] : nominal_chip_id, 
0074         // note : [1] : nominal_chan_id,
0075         // note : [2] : adc,
0076         // note : [3] : adc_conv
0077         // note : [4] : bco_diff
0078         vector<int> nominal_vec = {-1,-1,-1,-1,-1};
0079         vector<int> hit_seat[13][256]; 
0080         for (int i = 0; i < 13; i++){
0081             for (int i1 = 0; i1 < 256; i1++){
0082                 hit_seat[i][i1] = nominal_vec;
0083             }
0084         }
0085 
0086         vector<hit_pro_info>hit_pro_vec; hit_pro_vec.clear(); // note : have the position information
0087         vector<clu_info_private> output_vec; output_vec.clear();
0088 
0089         int num_hit = 0;
0090         double chan_truck = 0;
0091         double chan_truck_denominator = 0;
0092         double pos_x_truck = 0;
0093         double pos_x_truck_denominator = 0;
0094         double pos_y_truck = 0;
0095         double pos_y_truck_denominator = 0;
0096         int standard_channel;
0097         int distance_meter = 0;
0098         int sum_adc = 0;
0099         int sum_adc_conv = 0;
0100         vector<double> bco_diff_vec; bco_diff_vec.clear();
0101 
0102         // cout<<"test 3"<<endl;
0103         
0104         for (int i = 0; i < single_event.size(); i++) // note : number of hits in this event, for this half-ladder
0105         {
0106             // note : U1 ~ U13, 0 ~ 127. // U14 ~ U26, -> 128 ~ 255
0107             int chip_conv = ( single_event[i].chip_id > 13 ) ? single_event[i].chip_id - 13  : single_event[i].chip_id;
0108             int chan_conv = ( single_event[i].chip_id > 13 ) ? 255 - single_event[i].chan_id : single_event[i].chan_id;
0109 
0110             if (hit_seat[chip_conv - 1][chan_conv] == nominal_vec)
0111             {
0112                 hit_seat[chip_conv - 1][chan_conv] = {single_event[i].chip_id, single_event[i].chan_id, single_event[i].adc, single_event[i].adc_conv, single_event[i].bco_diff};
0113             }
0114             else // note : clone hit, but do nothing for now
0115             {
0116                 // cout<<"chip_id : "<<chip_conv<<" chan_id : "<<chan_conv<<" fired more than once ! N_hit in this HL : "<<single_event.size()<<" nominal_chipid : "<<single_event[i].chip_id<<" chan_id : "<<single_event[i].chan_id<<endl;
0117                 // note : take the latest one.
0118                 hit_seat[chip_conv - 1][chan_conv] = {single_event[i].chip_id, single_event[i].chan_id, single_event[i].adc, single_event[i].adc_conv, single_event[i].bco_diff};    
0119             }
0120 
0121             // cout<<"test 3-5 "<<single_event[i].chip_id<<" "<<single_event[i].chan_id<<endl;    
0122         }
0123         // cout<<"test 4"<<endl;
0124         
0125         // for (int col = 0; col < 13; col++) // note : column
0126         // {
0127         //     // cout<<" "<<endl;
0128         //     for (int ch = 0; ch < 256; ch++) // note : channel, remove those empty seat
0129         //     {
0130         //         cout<<"---------------- "<<col<<" "<<ch<<" "<<hit_seat[col][ch][0]<<" "<<hit_seat[col][ch][1]<<" "<<hit_seat[col][ch][2]<<" "<<hit_seat[col][ch][3]<<" "<<hit_seat[col][ch][4]<<" size : "<<hit_seat[col][ch].size()<<endl;
0131         //     }
0132         // }
0133 
0134         for (int col = 0; col < 13; col++) // note : column
0135         {
0136             // cout<<" "<<endl;
0137             for (int ch = 0; ch < 256; ch++) // note : channel, remove those empty seat
0138             {
0139                 if (hit_seat[col][ch][0] != -1 && hit_seat[col][ch][1] != -1 && hit_seat[col][ch][2] != -1 && hit_seat[col][ch][3] != -1 && hit_seat[col][ch][4] != -1 && hit_seat[col][ch].size() == 5)
0140                 {
0141                     // cout<<"test 4-5 "<<col<<" "<<ch<<endl;
0142                     // cout<<"test 4-5 "<<server_name<<" "<<FC_id<<" "<<hit_seat[col][ch][0]<<" "<<hit_seat[col][ch][1]<<endl;
0143                     pos_str hit_pos = ch_pos_DB -> Get_XY_all(server_name, FC_id, hit_seat[col][ch][0], hit_seat[col][ch][1]);
0144                     // cout<<"test 5"<<endl;
0145                     // cout<<" "<<endl;
0146 
0147                     // cout<<"!!!!!!!!!!!!!!!!!! test in clustering func "<<hit_pos.x<<" "<<hit_pos.y<<endl;
0148                     // cout<<"("<<hit_pos.x<<","<<hit_pos.y<<"),";
0149 
0150                     hit_pro_vec.push_back({
0151                         hit_seat[col][ch][0], // note : original chip_id
0152                         hit_seat[col][ch][1], // note : original chan_id
0153                         col + 1,              // note : column
0154                         ch,                   // note : conv_ch_id
0155                         hit_seat[col][ch][2], // note : adc
0156                         hit_seat[col][ch][3], // note : conv_adc
0157                         
0158                         hit_pos.x,            // note : nominal strip pos in sPHENIX coordinate 
0159                         hit_pos.y,            // note : nominal strip pos in sPHENIX coordinate 
0160                         hit_pos.z,            // note : nominal strip pos in sPHENIX coordinate
0161                         hit_pos.layer,        // note : N layer, 0 or 1.
0162                         
0163                         hit_seat[col][ch][4]  // note : bco_diff
0164                     });
0165                     // if (hit_seat[col][ch][3] > 1000){
0166                     //     cout<<"before clustering, hit info :\t"<<hit_pos.x<<" "<<hit_pos.y<<" "<<hit_pos.z<<"\toriginal chip/chan "<<hit_seat[col][ch][0]<<" "<<hit_seat[col][ch][1]<<"\tconverted chip/chan "<<col+1<<" "<<ch<<"\tadc & adc_conv "<<hit_seat[col][ch][2]<<" "<<hit_seat[col][ch][3]<<endl;
0167                     // }
0168                     
0169                 }
0170             } // note : end 256 chan check
0171 
0172             for (int hit_i = 0; hit_i < hit_pro_vec.size(); hit_i++)
0173             {
0174                 standard_channel         = hit_pro_vec[hit_i].chan_id_conv;
0175 
0176                 chan_truck              += hit_pro_vec[hit_i].chan_id_conv;
0177                 chan_truck_denominator  += 1;
0178 
0179                 pos_x_truck             += hit_pro_vec[hit_i].x * hit_pro_vec[hit_i].adc_conv;
0180                 pos_x_truck_denominator += hit_pro_vec[hit_i].adc_conv;
0181                 
0182                 pos_y_truck             += hit_pro_vec[hit_i].y * hit_pro_vec[hit_i].adc_conv;
0183                 pos_y_truck_denominator += hit_pro_vec[hit_i].adc_conv;
0184                 
0185                 num_hit                 += 1; 
0186                 sum_adc                 += hit_pro_vec[hit_i].adc;
0187                 sum_adc_conv            += hit_pro_vec[hit_i].adc_conv;
0188 
0189                 bco_diff_vec.push_back(hit_pro_vec[hit_i].bco_diff);
0190 
0191                 if (hit_pro_vec.size() - hit_i == 1) // note : for the case that only one hit in this column, and the "last single hit" in the column 
0192                 {
0193                     output_vec.push_back({
0194                         col + 1,  // note : column
0195                         chan_truck / chan_truck_denominator,
0196                         sum_adc,
0197                         sum_adc_conv,
0198                         num_hit,
0199 
0200                         pos_x_truck / pos_x_truck_denominator,
0201                         pos_y_truck / pos_y_truck_denominator,
0202                         hit_pro_vec[0].z,     // note : sPH-INTT nominal position
0203                         hit_pro_vec[0].layer, // note : layer
0204                         ((pos_y_truck / pos_y_truck_denominator) < 0) ? atan2((pos_y_truck / pos_y_truck_denominator),(pos_x_truck / pos_x_truck_denominator)) * (180./TMath::Pi()) + 360 : atan2((pos_y_truck / pos_y_truck_denominator),(pos_x_truck / pos_x_truck_denominator)) * (180./TMath::Pi()),
0205                         bco_diff_vec
0206                     });
0207                     // if (sum_adc_conv > 1000){
0208                     //     cout<<"~~~~ bug check 1, column : "<<col + 1<<" avg_chan : "<<chan_truck / chan_truck_denominator<<" sum_adc : "<<sum_adc <<" sum_adc_conv : "<<sum_adc_conv <<" size : "<<num_hit <<" avg_posX : "<<pos_x_truck / pos_x_truck_denominator <<" avg_posY : "<<pos_y_truck / pos_y_truck_denominator <<" Z : "<<hit_pro_vec[0].z<<" layer : "<<hit_pro_vec[0].layer<<endl;
0209                     // }
0210                     // cout<<"~~~~~~ test clustering func, "<<pos_x_truck / pos_x_truck_denominator<<" "<<pos_y_truck / pos_y_truck_denominator<<endl;
0211                     // cout<<"("<<pos_x_truck/pos_x_truck_denominator<<","<<pos_y_truck/pos_y_truck_denominator<<"),";
0212                 }
0213 
0214                 // note : this for loop will be skipped if it's single hit
0215                 for (int hit_i1 = 0; hit_i1 < hit_pro_vec.size() - (hit_i + 1); hit_i1++)
0216                 {
0217                     if ( fabs(standard_channel - hit_pro_vec[hit_i + hit_i1 + 1].chan_id_conv) == hit_i1 + 1 )
0218                     {
0219                         chan_truck              += hit_pro_vec[hit_i + hit_i1 + 1].chan_id_conv;
0220                         chan_truck_denominator  += 1;
0221 
0222                         pos_x_truck             += hit_pro_vec[hit_i + hit_i1 + 1].x * hit_pro_vec[hit_i + hit_i1 + 1].adc_conv;
0223                         pos_x_truck_denominator += hit_pro_vec[hit_i + hit_i1 + 1].adc_conv;
0224                         
0225                         pos_y_truck             += hit_pro_vec[hit_i + hit_i1 + 1].y * hit_pro_vec[hit_i + hit_i1 + 1].adc_conv;
0226                         pos_y_truck_denominator += hit_pro_vec[hit_i + hit_i1 + 1].adc_conv;
0227                         
0228                         num_hit                 += 1; 
0229                         sum_adc                 += hit_pro_vec[hit_i + hit_i1 + 1].adc;
0230                         sum_adc_conv            += hit_pro_vec[hit_i + hit_i1 + 1].adc_conv;
0231 
0232                         bco_diff_vec.push_back(hit_pro_vec[hit_i].bco_diff);
0233 
0234                         distance_meter += 1;
0235 
0236                         if ((hit_pro_vec.size() - (hit_i + 1) - hit_i1) == 1) // note : the last non single-hit cluster
0237                         {
0238                             output_vec.push_back({
0239                                 col + 1,  // note : column
0240                                 chan_truck / chan_truck_denominator,
0241                                 sum_adc,
0242                                 sum_adc_conv,
0243                                 num_hit,
0244 
0245                                 pos_x_truck / pos_x_truck_denominator,
0246                                 pos_y_truck / pos_y_truck_denominator,
0247                                 hit_pro_vec[0].z,
0248                                 hit_pro_vec[0].layer, // note : layer
0249                                 ((pos_y_truck / pos_y_truck_denominator) < 0) ? atan2((pos_y_truck / pos_y_truck_denominator),(pos_x_truck / pos_x_truck_denominator)) * (180./TMath::Pi()) + 360 : atan2((pos_y_truck / pos_y_truck_denominator),(pos_x_truck / pos_x_truck_denominator)) * (180./TMath::Pi()),
0250                                 bco_diff_vec
0251                             });
0252                             // if (sum_adc_conv > 1000){
0253                             //     cout<<"~~~~ bug check 2, column : "<<col + 1<<" avg_chan : "<<chan_truck / chan_truck_denominator<<" sum_adc : "<<sum_adc <<" sum_adc_conv : "<<sum_adc_conv <<" size : "<<num_hit <<" avg_posX : "<<pos_x_truck / pos_x_truck_denominator <<" avg_posY : "<<pos_y_truck / pos_y_truck_denominator <<" Z : "<<hit_pro_vec[0].z<<" layer : "<<hit_pro_vec[0].layer<<endl;
0254                             // }
0255 
0256                             // cout<<"~~~~~~ test clustering func, "<<pos_x_truck / pos_x_truck_denominator<<" "<<pos_y_truck / pos_y_truck_denominator<<endl;
0257                             // cout<<"("<<pos_x_truck/pos_x_truck_denominator<<","<<pos_y_truck/pos_y_truck_denominator<<"),";
0258                         }
0259 
0260                     }
0261                     else 
0262                     {
0263                         output_vec.push_back({
0264                             col + 1,  // note : column
0265                             chan_truck / chan_truck_denominator,
0266                             sum_adc,
0267                             sum_adc_conv,
0268                             num_hit,
0269 
0270                             pos_x_truck / pos_x_truck_denominator,
0271                             pos_y_truck / pos_y_truck_denominator,
0272                             hit_pro_vec[0].z,
0273                             hit_pro_vec[0].layer, // note : layer
0274                             ((pos_y_truck / pos_y_truck_denominator) < 0) ? atan2((pos_y_truck / pos_y_truck_denominator),(pos_x_truck / pos_x_truck_denominator)) * (180./TMath::Pi()) + 360 : atan2((pos_y_truck / pos_y_truck_denominator),(pos_x_truck / pos_x_truck_denominator)) * (180./TMath::Pi()),
0275                             bco_diff_vec
0276                         });
0277                         // if (sum_adc_conv > 1000){
0278                         //     cout<<"~~~~ bug check 3, column : "<<col + 1<<" avg_chan : "<<chan_truck / chan_truck_denominator<<" sum_adc : "<<sum_adc <<" sum_adc_conv : "<<sum_adc_conv <<" size : "<<num_hit <<" avg_posX : "<<pos_x_truck / pos_x_truck_denominator <<" avg_posY : "<<pos_y_truck / pos_y_truck_denominator <<" Z : "<<hit_pro_vec[0].z<<" layer : "<<hit_pro_vec[0].layer<<endl;
0279                         // }
0280                         // cout<<"~~~~~~ test clustering func, "<<pos_x_truck / pos_x_truck_denominator<<" "<<pos_y_truck / pos_y_truck_denominator<<endl;
0281                         // cout<<"("<<pos_x_truck/pos_x_truck_denominator<<","<<pos_y_truck/pos_y_truck_denominator<<"),";
0282 
0283                         break;
0284                     }
0285 
0286                 } // note : end : n_hit i1
0287 
0288                 hit_i += distance_meter;
0289                 distance_meter = 0;
0290                 chan_truck = 0;
0291                 chan_truck_denominator = 0;
0292 
0293                 pos_x_truck = 0;             
0294                 pos_x_truck_denominator = 0; 
0295                 
0296                 pos_y_truck = 0;             
0297                 pos_y_truck_denominator = 0; 
0298                 
0299                 num_hit = 0;                 
0300                 sum_adc = 0;                 
0301                 sum_adc_conv = 0;    
0302 
0303                 bco_diff_vec.clear();        
0304 
0305             } // note : end n_hit in single column
0306 
0307             hit_pro_vec.clear();
0308 
0309         } // note : end column
0310 
0311         return output_vec;
0312     }
0313 
0314     pos_str test_func(InttConversion * ch_pos_DB){
0315         // cout<<"In InttClustering.h, test_func : "<< ch_pos_DB -> GetGeoMode()<<endl;
0316 
0317         return ch_pos_DB -> Get_XY_all("intt0", 0, 1, 127);
0318     }
0319 
0320 };
0321 
0322 #endif