File indexing completed on 2025-08-06 08:12:49
0001 #ifndef __INTTCLUSTERING_H_
0002 #define __INTTCLUSTERING_H_
0003
0004
0005
0006 struct clu_info {
0007 int column;
0008
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
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
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;
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;
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
0074
0075
0076
0077
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();
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
0103
0104 for (int i = 0; i < single_event.size(); i++)
0105 {
0106
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
0115 {
0116
0117
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
0122 }
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134 for (int col = 0; col < 13; col++)
0135 {
0136
0137 for (int ch = 0; ch < 256; ch++)
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
0142
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
0145
0146
0147
0148
0149
0150 hit_pro_vec.push_back({
0151 hit_seat[col][ch][0],
0152 hit_seat[col][ch][1],
0153 col + 1,
0154 ch,
0155 hit_seat[col][ch][2],
0156 hit_seat[col][ch][3],
0157
0158 hit_pos.x,
0159 hit_pos.y,
0160 hit_pos.z,
0161 hit_pos.layer,
0162
0163 hit_seat[col][ch][4]
0164 });
0165
0166
0167
0168
0169 }
0170 }
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)
0192 {
0193 output_vec.push_back({
0194 col + 1,
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,
0203 hit_pro_vec[0].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
0208
0209
0210
0211
0212 }
0213
0214
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)
0237 {
0238 output_vec.push_back({
0239 col + 1,
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,
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
0253
0254
0255
0256
0257
0258 }
0259
0260 }
0261 else
0262 {
0263 output_vec.push_back({
0264 col + 1,
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,
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
0278
0279
0280
0281
0282
0283 break;
0284 }
0285
0286 }
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 }
0306
0307 hit_pro_vec.clear();
0308
0309 }
0310
0311 return output_vec;
0312 }
0313
0314 pos_str test_func(InttConversion * ch_pos_DB){
0315
0316
0317 return ch_pos_DB -> Get_XY_all("intt0", 0, 1, 127);
0318 }
0319
0320 };
0321
0322 #endif