Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // #include "DAC_Scan_ladder.h"
0002 //#include "InttConversion.h"
0003 #include "/sphenix/user/ChengWei/INTT/INTT_commissioning/INTT_CW/INTT_commissioning/DAC_Scan/InttConversion_new.h"
0004 #include "/sphenix/user/ChengWei/INTT/INTT_commissioning/INTT_CW/INTT_commissioning/DAC_Scan/InttClustering.h"
0005 #include "sigmaEff.h"
0006 #include "sPhenixStyle.C"
0007 
0008 // todo : the number of number is given by the adc_setting_run !!!
0009 // todo : also the range of the hist.
0010 // todo : the adc follows the following convention
0011 // todo : 1. the increment has to be 4
0012 // todo : remember to check the "adc_conv"
0013 // vector<vector<int>> adc_setting_run = {  
0014 //     // {8  , 12 , 16 , 20 , 24 , 28 , 32 , 36 },
0015 //     // {28 , 32 , 36 , 40 , 44 , 48 , 52 , 56 },
0016 //     {48 , 52 , 56 , 60 , 64 , 68 , 72 , 76 }, // note : 3
0017 //     {68 , 72 , 76 , 80 , 84 , 88 , 92 , 96 }, // note : 4
0018 //     {88 , 92 , 96 , 100, 104, 108, 112, 116}, // note : 5
0019 //     {108, 112, 116, 120, 124, 128, 132, 136}, // note : 6
0020 //     {128, 132, 136, 140, 144, 148, 152, 156}, // note : 7
0021 //     // {148, 152, 156, 160, 164, 168, 172, 176},
0022 //     // {168, 172, 176, 180, 184, 188, 192, 196},
0023 //     // {188, 192, 196, 200, 204, 208, 212, 216}
0024 // };
0025 
0026 vector<vector<int>> adc_setting_run = { 
0027     {15, 30, 60, 90, 120, 150, 180, 210, 240}
0028     // {15, 30, 50, 70, 90, 110, 130, 150,170}
0029     // {8  , 12 , 16 , 20 , 24 , 28 , 32 , 36 },
0030     // {28 , 32 , 36 , 40 , 44 , 48 , 52 , 56 },
0031     // {48 , 52 , 56 , 60 , 64 , 68 , 72 , 76 }, // note : 3
0032     // {68 , 72 , 76 , 80 , 84 , 88 , 92 , 96 }, // note : 4
0033     // {88 , 92 , 96 , 100, 104, 108, 112, 116}, // note : 5
0034     // {108, 112, 116, 120, 124, 128, 132, 136}, // note : 6
0035     // {128, 132, 136, 140, 144, 148, 152, 156}, // note : 7
0036     // {148, 152, 156, 160, 164, 168, 172, 176},
0037     // {168, 172, 176, 180, 184, 188, 192, 196},
0038     // {188, 192, 196, 200, 204, 208, 212, 216}
0039 };
0040 
0041 TString color_code_2[8] = {"#CC768D","#19768D","#DDA573","#009193","#6E9193","#941100","#A08144","#517E66"};
0042 
0043 struct full_hit_info {
0044     int FC;
0045     int chip_id;
0046     int chan_id;
0047     int adc;
0048 };
0049 
0050 
0051 struct ladder_info {
0052     int FC;
0053     TString Port;
0054     int ROC;
0055     int Direction; // note : 0 : south, 1 : north 
0056 };
0057 
0058 double gaus_func(double *x, double *par)
0059 {
0060     // note : par[0] : size
0061     // note : par[1] : mean
0062     // note : par[2] : width
0063     // note : par[3] : offset 
0064     return par[0] * TMath::Gaus(x[0],par[1],par[2]) + par[3];
0065 }
0066 
0067 double double_gaus_func(double *x, double *par)
0068 {
0069     // note : par[0] : size of gaus1
0070     // note : par[1] : mean of gaus1
0071     // note : par[2] : width of gaus1
0072     // note : par[3] : offset of gaus1 
0073 
0074     // note : par[4] : size of gaus2
0075     // note : par[5] : mean of gaus2
0076     // note : par[6] : width of gaus2
0077 
0078     double gaus1 = par[0] * TMath::Gaus(x[0],par[1],par[2]) + par[3]; 
0079     double gaus2 = par[4] * TMath::Gaus(x[0],par[5],par[6]); 
0080 
0081     return gaus1 + gaus2;
0082 }
0083 
0084 double get_radius(double x, double y)
0085 {
0086     return sqrt(pow(x,2)+pow(y,2));
0087 }
0088 
0089 double get_radius_sign(double x, double y)
0090 {
0091     double phi = ((y) < 0) ? atan2((y),(x)) * (180./TMath::Pi()) + 360 : atan2((y),(x)) * (180./TMath::Pi());
0092     
0093     return (phi > 180) ? sqrt(pow(x,2)+pow(y,2)) * -1 : sqrt(pow(x,2)+pow(y,2)); 
0094 }
0095 
0096 double sin_func(double *x, double *par)
0097 {
0098     return par[0] * sin(par[1] * x[0] + par[2]) + par[3];
0099 }
0100 
0101 double cos_func(double *x, double *par)
0102 {
0103     return -1 * par[0] * cos(par[1] * (x[0] + par[2])) + par[3];
0104 }
0105 
0106 void Characterize_Pad (TPad *pad, float left = 0.15, float right = 0.1, float top = 0.1, float bottom = 0.12, bool set_logY = false, int setgrid_bool = 0)
0107 {
0108     if (setgrid_bool == true) {pad -> SetGrid (1, 1);}
0109     pad -> SetLeftMargin   (left);
0110     pad -> SetRightMargin  (right);
0111     pad -> SetTopMargin    (top);
0112     pad -> SetBottomMargin (bottom);
0113     pad -> SetTicks(1,1);
0114     if (set_logY == true)
0115     {
0116         pad -> SetLogy (1);
0117     }
0118     
0119 }
0120 
0121 std::vector<double> calculateDistanceAndClosestPoint(double x1, double y1, double x2, double y2, double target_x, double target_y) {
0122     
0123     if (x1 != x2)
0124     {
0125         // Calculate the slope and intercept of the line passing through (x1, y1) and (x2, y2)
0126         double a = (y2 - y1) / (x2 - x1);
0127         double b = y1 - a * x1;
0128 
0129         // cout<<"slope : y="<<a<<"x+"<<b<<endl;
0130         
0131         // Calculate the closest distance from (target_x, target_y) to the line y = ax + b
0132         double closest_distance = std::abs(a * target_x - target_y + b) / std::sqrt(a * a + 1);
0133 
0134         // Calculate the coordinates of the closest point (Xc, Yc) on the line y = ax + b
0135         double Xc = (target_x + a * target_y - a * b) / (a * a + 1);
0136         double Yc = a * Xc + b;
0137 
0138         return { closest_distance, Xc, Yc };
0139     }
0140     else 
0141     {
0142         double closest_distance = std::abs(x1 - target_x);
0143         double Xc = x1;
0144         double Yc = target_y;
0145 
0146         return { closest_distance, Xc, Yc };
0147     }
0148     
0149     
0150 }
0151 
0152 double get_z_vertex(clu_info inner_clu, clu_info outer_clu, double target_x, double target_y)
0153 {
0154     // note : x = z, 
0155     // note : y = radius
0156     double inner_clu_r = sqrt(pow(inner_clu.x,2)+ pow(inner_clu.y,2));
0157     double outer_clu_r = sqrt(pow(outer_clu.x,2)+ pow(outer_clu.y,2));
0158     double target_r    = sqrt(pow(target_x,2)   + pow(target_y,2));
0159 
0160     // Use the slope equation (y = ax + b) to calculate the x-coordinate for the target y
0161     if ( fabs(outer_clu.z - inner_clu.z) < 0.00001 ){
0162         return outer_clu.z;
0163     }
0164     else {
0165         double slope = (outer_clu_r - inner_clu_r) / (outer_clu.z - inner_clu.z);
0166         double yIntercept = inner_clu_r - slope * inner_clu.z;
0167         double xCoordinate = (target_r - yIntercept) / slope;
0168         return xCoordinate;
0169     }
0170     
0171 }
0172 
0173 // Function to calculate the angle between two vectors in degrees using the cross product
0174 double calculateAngleBetweenVectors(double x1, double y1, double x2, double y2, double targetX, double targetY) {
0175     // Calculate the vectors vector_1 (point_1 to point_2) and vector_2 (point_1 to target)
0176     double vector1X = x2 - x1;
0177     double vector1Y = y2 - y1;
0178 
0179     double vector2X = targetX - x1;
0180     double vector2Y = targetY - y1;
0181 
0182     // Calculate the cross product of vector_1 and vector_2 (z-component)
0183     double crossProduct = vector1X * vector2Y - vector1Y * vector2X;
0184     
0185     // cout<<" crossProduct : "<<crossProduct<<endl;
0186 
0187     // Calculate the magnitudes of vector_1 and vector_2
0188     double magnitude1 = std::sqrt(vector1X * vector1X + vector1Y * vector1Y);
0189     double magnitude2 = std::sqrt(vector2X * vector2X + vector2Y * vector2Y);
0190 
0191     // Calculate the angle in radians using the inverse tangent of the cross product and dot product
0192     double dotProduct = vector1X * vector2X + vector1Y * vector2Y;
0193 
0194     double angleInRadians = std::atan2(std::abs(crossProduct), dotProduct);
0195     // Convert the angle from radians to degrees and return it
0196     double angleInDegrees = angleInRadians * 180.0 / M_PI;
0197     
0198     double angleInRadians_new = std::asin( crossProduct/(magnitude1*magnitude2) );
0199     double angleInDegrees_new = angleInRadians_new * 180.0 / M_PI;
0200     
0201     // cout<<"angle : "<<angleInDegrees_new<<endl;
0202 
0203     double DCA_distance = sin(angleInRadians_new) * magnitude2;
0204 
0205     return DCA_distance;
0206 }
0207 
0208 void temp_bkg(TPad * c1, string conversion_mode, double peek, pair<double,double> beam_origin, InttConversion * ch_pos_DB)
0209 {
0210     c1 -> cd();
0211 
0212     int N_ladder[4] = {12, 12, 16, 16};
0213     string ladder_index_string[16] = {"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15"};
0214 
0215     vector<double> x_vec; x_vec.clear();
0216     vector<double> y_vec; y_vec.clear();
0217 
0218     vector<double> x_vec_2; x_vec_2.clear();
0219     vector<double> y_vec_2; y_vec_2.clear();
0220 
0221     TGraph * bkg = new TGraph();
0222     bkg -> SetTitle("INTT event display X-Y plane");
0223     bkg -> SetMarkerStyle(20);
0224     bkg -> SetMarkerSize(0.1);
0225     bkg -> SetPoint(0,0,0);
0226     bkg -> SetPoint(1,beam_origin.first,beam_origin.second);
0227     bkg -> GetXaxis() -> SetLimits(-150,150);
0228     bkg -> GetYaxis() -> SetRangeUser(-150,150);
0229     bkg -> GetXaxis() -> SetTitle("X [mm]");
0230     bkg -> GetYaxis() -> SetTitle("Y [mm]");
0231     
0232     bkg -> Draw("ap");
0233 
0234     TLine * ladder_line = new TLine();
0235     ladder_line -> SetLineWidth(1);
0236 
0237     for (int server_i = 0; server_i < 4; server_i++)
0238     {
0239         for (int FC_i = 0; FC_i < 14; FC_i++)
0240         {
0241             ladder_line -> DrawLine(
0242                 ch_pos_DB -> Get_XY_all(Form("intt%i",server_i),FC_i,14,0).x, ch_pos_DB -> Get_XY_all(Form("intt%i",server_i),FC_i,14,0).y,
0243                 ch_pos_DB -> Get_XY_all(Form("intt%i",server_i),FC_i,1,0).x, ch_pos_DB -> Get_XY_all(Form("intt%i",server_i),FC_i,1,0).y
0244             );
0245         }
0246     }
0247     
0248     ladder_line -> Draw("l same");
0249 
0250 }
0251 
0252 double grEY_stddev (TGraphErrors * input_grr)
0253 {
0254     vector<double> input_vector; input_vector.clear();
0255     for (int i = 0; i < input_grr -> GetN(); i++)
0256     {  
0257         input_vector.push_back( input_grr -> GetPointY(i) );
0258     }
0259 
0260     double sum=0;
0261     double average;
0262     double sum_subt = 0;
0263     for (int i=0; i<input_vector.size(); i++)
0264         {
0265             sum+=input_vector[i];
0266 
0267         }
0268     average=sum/input_vector.size();
0269     //cout<<"average is : "<<average<<endl;
0270 
0271     for (int i=0; i<input_vector.size(); i++)
0272         {
0273             //cout<<input_vector[i]-average<<endl;
0274             sum_subt+=pow((input_vector[i]-average),2);
0275 
0276         }
0277     //cout<<"sum_subt : "<<sum_subt<<endl;
0278     double stddev;
0279     stddev=sqrt(sum_subt/(input_vector.size()-1));  
0280     return stddev;
0281 }   
0282 
0283 pair<double, double> mirrorPolynomial(double a, double b) {
0284     // Interchange 'x' and 'y'
0285     double mirroredA = 1.0 / a;
0286     double mirroredB = -b / a;
0287 
0288     return {mirroredA, mirroredB};
0289 }
0290 
0291 // note : pair<reduced chi2, eta of the track>
0292 // note : vector : {r,z}
0293 // note : p0 : vertex point {r,z,zerror}
0294 // note : p1 : inner layer
0295 // note : p2 : outer layer
0296 pair<double,double> Get_eta(vector<double>p0, vector<double>p1, vector<double>p2)
0297 {
0298     vector<double> r_vec  = {p0[0], p1[0], p2[0]}; 
0299     vector<double> z_vec  = {p0[1], p1[1], p2[1]}; 
0300     vector<double> re_vec = {0, 0, 0}; 
0301     vector<double> ze_vec = {p0[2], ( fabs( p1[1] ) < 130 ) ? 8. : 10., ( fabs( p2[1] ) < 130 ) ? 8. : 10.}; 
0302 
0303     // note : swap the r and z, to have easier fitting 
0304     // note : in principle, Z should be in the x axis, R should be in the Y axis
0305     TGraphErrors * track_gr = new TGraphErrors(3,&r_vec[0],&z_vec[0],&re_vec[0],&ze_vec[0]);    
0306     
0307     double vertical_line = ( fabs( grEY_stddev(track_gr) ) < 0.00001 ) ? 1 : 0;
0308     
0309     if (vertical_line) {return {0,0};}
0310     else 
0311     {
0312         TF1 * fit_rz = new TF1("fit_rz","pol1",-500,500);
0313         fit_rz -> SetParameters(0,0);
0314 
0315         track_gr -> Fit(fit_rz,"NQ");
0316 
0317         pair<double,double> ax_b = mirrorPolynomial(fit_rz -> GetParameter(1),fit_rz -> GetParameter(0));
0318 
0319         return  {(fit_rz -> GetChisquare() / double(fit_rz -> GetNDF())), -1 * TMath::Log( fabs( tan( atan2(ax_b.first, (ax_b.first > 0) ? 1. : -1. ) / 2 ) ) )};
0320 
0321     }
0322 
0323 }
0324 
0325 // note : vector : {r,z}
0326 // note : p0 : vertex point {r,z,zerror}
0327 // note : p1 : another point from detector
0328 // note : since only two points -> no strip width considered
0329 double Get_eta_2P(vector<double>p0, vector<double>p1)
0330 {
0331     // vector<double> r_vec  = {p0[0], p1[0]}; 
0332     // vector<double> z_vec  = {p0[1], p1[1]}; 
0333     // vector<double> re_vec = {0, 0}; 
0334     // vector<double> ze_vec = {p0[2], ( fabs( p1[1] ) < 130 ) ? 8. : 10.}; 
0335 
0336     // note : swap the r and z, to have easier fitting 
0337     // note : in principle, Z should be in the x axis, R should be in the Y axis
0338     // TGraphErrors * track_gr = new TGraphErrors(3,&r_vec[0],&z_vec[0],&re_vec[0],&ze_vec[0]);    
0339     
0340     // double vertical_line = ( fabs( grEY_stddev(track_gr) ) < 0.00001 ) ? 1 : 0;
0341     
0342     return  -1 * TMath::Log( fabs( tan( atan2(p1[0] - p0[0], p1[1] - p0[1]) / 2 ) ) );
0343 
0344     // if (vertical_line) {return 0;}
0345     // else 
0346     // {
0347     //     TF1 * fit_rz = new TF1("fit_rz","pol1",-500,500);
0348     //     fit_rz -> SetParameters(0,0);
0349 
0350     //     track_gr -> Fit(fit_rz,"NQ");
0351 
0352     //     pair<double,double> ax_b = mirrorPolynomial(fit_rz -> GetParameter(1),fit_rz -> GetParameter(0));
0353     // }
0354 
0355 }
0356 
0357 double Get_extrapolation(double given_y, double p0x, double p0y, double p1x, double p1y) // note : x : z, y : r
0358 {
0359     if ( fabs(p0x - p1x) < 0.00001 ){ // note : the line is vertical (if z is along the x axis)
0360         return p0x;
0361     }
0362     else {
0363         double slope = (p1y - p0y) / (p1x - p0x);
0364         double yIntercept = p0y - slope * p0x;
0365         double xCoordinate = (given_y - yIntercept) / slope;
0366         return xCoordinate;
0367     }
0368 }
0369 
0370 pair<double,double> Get_possible_zvtx(double rvtx, vector<double> p0, vector<double> p1) // note : inner p0, outer p1, vector {r,z}, -> {y,x}
0371 {
0372     vector<double> p0_z_edge = { ( fabs( p0[1] ) < 130 ) ? p0[1] - 8. : p0[1] - 10., ( fabs( p0[1] ) < 130 ) ? p0[1] + 8. : p0[1] + 10.}; // note : vector {left edge, right edge}
0373     vector<double> p1_z_edge = { ( fabs( p1[1] ) < 130 ) ? p1[1] - 8. : p1[1] - 10., ( fabs( p1[1] ) < 130 ) ? p1[1] + 8. : p1[1] + 10.}; // note : vector {left edge, right edge}
0374 
0375     double edge_first  = Get_extrapolation(rvtx,p0_z_edge[0],p0[0],p1_z_edge[1],p1[0]);
0376     double edge_second = Get_extrapolation(rvtx,p0_z_edge[1],p0[0],p1_z_edge[0],p1[0]);
0377 
0378     double mid_point = (edge_first + edge_second) / 2.;
0379     double possible_width = fabs(edge_first - edge_second) / 2.;
0380 
0381     return {mid_point, possible_width}; // note : first : mid point, second : width
0382 
0383 }
0384 
0385 void TH2F_threshold(TH2F * input_hist, double threshold)
0386 {
0387     for (int xi = 0; xi < input_hist -> GetNbinsX(); xi++){
0388         for(int yi = 0; yi < input_hist -> GetNbinsY(); yi++){
0389             if (input_hist -> GetBinContent(xi + 1, yi +1) < threshold){ input_hist -> SetBinContent(xi + 1, yi +1, 0); }
0390         }
0391     }
0392 } 
0393 
0394 // note : use "ls *.root > file_list.txt" to create the list of the file in the folder, full directory in the file_list.txt
0395 // note : set_folder_name = "folder_xxxx"
0396 // note : server_name = "inttx"
0397 void INTT_xyvtx(string run_ID, int geo_mode_id, string file_event, bool full_event, int run_Nevent)
0398 {
0399     
0400     SetsPhenixStyle();
0401 
0402     TCanvas * c4 = new TCanvas("","",1200,800);    
0403     c4 -> cd();
0404     
0405     TCanvas * c2 = new TCanvas("","",2500,800);    
0406     c2 -> cd();
0407     TPad *pad_xy = new TPad(Form("pad_xy"), "", 0.0, 0.0, 0.33, 1.0);
0408     Characterize_Pad(pad_xy, 0.15, 0.1, 0.1, 0.1 , 0, 0);
0409     pad_xy -> Draw();
0410 
0411     TPad *pad_rz = new TPad(Form("pad_rz"), "", 0.33, 0.0, 0.66, 1.0);
0412     Characterize_Pad(pad_rz, 0.15, 0.1, 0.1, 0.1 , 0, 0);
0413     pad_rz -> Draw();
0414 
0415     TPad *pad_z = new TPad(Form("pad_z"), "", 0.66, 0.0, 1.0, 1.0);
0416     Characterize_Pad(pad_z, 0.15, 0.1, 0.1, 0.1 , 0, 0);
0417     pad_z -> Draw();
0418 
0419     TCanvas * c1 = new TCanvas("","",950,800);
0420     c1 -> cd();
0421 
0422     //todo : can be more than it, possibly
0423     vector<string> conversion_mode_BD = {"ideal", "survey_1_XYAlpha_Peek_3.32mm", "full_survey_3.32"};
0424     // vector<string> conversion_mode_BD = {"ideal", "survey_1_XYAlpha_Peek", "full_survey_3.32"};
0425     
0426     // string mother_folder_directory = "/home/phnxrc/INTT/cwshih/DACscan_data/zero_magnet_Takashi_used";
0427     // string file_name = "beam_inttall-00020869-0000_event_base_ana_cluster_ideal_excludeR1500_100kEvent";
0428     // string file_name = "beam_inttall-00020869-0000_event_base_ana_cluster_survey_1_XYAlpha_Peek_3.32mm_excludeR1500_100kEvent";
0429 
0430     // string run_ID = "20869"; string file_event = "150";
0431     // todo : change the file name.
0432     string mother_folder_directory = "/sphenix/user/ChengWei/INTT/INTT_commissioning/ZeroField/" + run_ID;
0433     // string file_name = "beam_inttall-000" +run_ID+ "-0000_event_base_ana_cluster_survey_1_XYAlpha_Peek_3.32mm_excludeR20000_"+ file_event +"kEvent_3HotCut";
0434     string file_name = "beam_inttall-000" +run_ID+ "-0000_event_base_ana_cluster_"+ conversion_mode_BD[geo_mode_id] +"_excludeR1500_"+ file_event +"kEvent_3HotCut";
0435 
0436     cout<<"the input file name : "<<file_name<<endl;
0437     sleep(5);
0438 
0439     // string mother_folder_directory = "/home/phnxrc/INTT/cwshih/DACscan_data/new_DAC_Scan_0722/AllServer/DAC2";
0440     // string file_name = "beam_inttall-00023058-0000_event_base_ana_cluster_ideal_excludeR2000_100kEvent";
0441 
0442     system(Form("mkdir %s/folder_%s_advanced",mother_folder_directory.c_str(),file_name.c_str()));
0443     system(Form("mkdir %s/folder_%s_advanced/good_track",mother_folder_directory.c_str(),file_name.c_str()));
0444 
0445     pair<double,double> beam_origin = {-0.457 + 0.0276, 2.657 - 0.2814}; // note : for run20869
0446     // pair<double,double> beam_origin_U = {0.0004, 0.0035}; // note : for run20869, the uncertainty of the VTXxy, calculated by the fit errors with the error propagation
0447     // pair<double,double> beam_origin = {-0.457, 2.657};
0448     // pair<double,double> beam_origin = {0.0, -2.0};
0449     double temp_Y_align = 0.;
0450     double temp_X_align = -0.;
0451 
0452     double zvtx_hist_l = -500;
0453     double zvtx_hist_r = 500;
0454 
0455     int Nhit_cut = 1500;           // note : if (> Nhit_cut)          -> continue
0456     int Nhit_cutl = 100;          // note : if (< Nhit_cutl)         -> continue 
0457     int clu_size_cut = 4;           // note : if (> clu_size_cut)      -> continue
0458     double clu_sum_adc_cut = 31;    // note : if (< clu_sum_adc_cut)   -> continue
0459     int N_clu_cut = 15000;          // note : if (> N_clu_cut)         -> continue  unit number
0460     int N_clu_cutl = 0;           // note : if (< N_clu_cutl)        -> continue  unit number
0461     double phi_diff_cut = 5.72;      // note : if (< phi_diff_cut)      -> pass      unit degree
0462     double DCA_cut = 4;             // note : if (< DCA_cut)           -> pass      unit mm
0463     int zvtx_cal_require = 15;      // note : if (> zvtx_cal_require)  -> pass
0464     int zvtx_draw_requireL = 15;       
0465     int zvtx_draw_requireR = 40000;   // note : if ( zvtx_draw_requireL < event && event < zvtx_draw_requireR) -> pass
0466     double Integrate_portion = 0.4; // todo : it was 0.6826, try to require less event, as most of the tracklets are not that useful
0467     double Integrate_portion_final = 0.68;
0468     bool draw_event_display = false;
0469     int print_rate = 5;
0470 
0471     // double mean_zvtx = -195.45; // note : unit : mm
0472 
0473     // bool full_event = false;
0474     long long used_event = run_Nevent;
0475 
0476     // double dNdeta_upper_range = 20;
0477 
0478     // todo : change the geo draw mode if needed
0479     int geo_mode_id_draw = 1;
0480     string conversion_mode = (geo_mode_id_draw == 0) ? "ideal" : "survey_1_XYAlpha_Peek";
0481     double peek = 3.32405;
0482 
0483     // note : the initiator of the INTT geometry class
0484     InttConversion * ch_pos_DB = new InttConversion(conversion_mode_BD[geo_mode_id], peek);
0485 
0486     TFile * file_in = new TFile(Form("%s/%s.root",mother_folder_directory.c_str(),file_name.c_str()),"read");
0487     TTree * tree = (TTree *)file_in->Get("tree_clu");
0488     
0489     long long N_event = (full_event == true) ? tree -> GetEntries() : used_event;
0490     cout<<Form("N_event in file %s : %lli",file_name.c_str(), N_event)<<endl;
0491 
0492     int N_hits;
0493     int N_cluster_inner;
0494     int N_cluster_outer;
0495     Long64_t bco_full;
0496     vector<int>* column_vec = new vector<int>();
0497     vector<double>* avg_chan_vec = new vector<double>();
0498     vector<int>* sum_adc_vec = new vector<int>();
0499     vector<int>* sum_adc_conv_vec = new vector<int>();
0500     vector<int>* size_vec = new vector<int>();
0501     vector<double>* x_vec = new vector<double>();
0502     vector<double>* y_vec = new vector<double>();
0503     vector<double>* z_vec = new vector<double>();
0504     vector<int>* layer_vec = new vector<int>();
0505     vector<double>* phi_vec = new vector<double>();
0506 
0507     tree -> SetBranchStatus("*",0);
0508     tree -> SetBranchStatus("nhits",1);
0509     tree -> SetBranchStatus("nclu_inner",1);
0510     tree -> SetBranchStatus("nclu_outer",1);
0511     // tree -> SetBranchStatus("bco_full",1);
0512     tree -> SetBranchStatus("column",1);
0513     tree -> SetBranchStatus("avg_chan",1);
0514     tree -> SetBranchStatus("sum_adc",1);
0515     tree -> SetBranchStatus("sum_adc_conv",1);
0516     tree -> SetBranchStatus("size",1);
0517     tree -> SetBranchStatus("x",1);
0518     tree -> SetBranchStatus("y",1);
0519     tree -> SetBranchStatus("z",1);
0520     tree -> SetBranchStatus("layer",1);
0521     tree -> SetBranchStatus("phi",1);
0522 
0523 
0524     tree -> SetBranchAddress("nhits",&N_hits);
0525     tree -> SetBranchAddress("nclu_inner",&N_cluster_inner);
0526     tree -> SetBranchAddress("nclu_outer",&N_cluster_outer);
0527     // tree -> SetBranchAddress("bco_full",&bco_full);
0528     tree -> SetBranchAddress("column", &column_vec);
0529     tree -> SetBranchAddress("avg_chan", &avg_chan_vec);
0530     tree -> SetBranchAddress("sum_adc", &sum_adc_vec);
0531     tree -> SetBranchAddress("sum_adc_conv", &sum_adc_conv_vec);
0532     tree -> SetBranchAddress("size", &size_vec);
0533     tree -> SetBranchAddress("x", &x_vec);
0534     tree -> SetBranchAddress("y", &y_vec);
0535     tree -> SetBranchAddress("z", &z_vec);
0536     tree -> SetBranchAddress("layer", &layer_vec);
0537     tree -> SetBranchAddress("phi", &phi_vec);
0538 
0539     TLatex *draw_text = new TLatex();
0540     draw_text -> SetNDC();
0541     draw_text -> SetTextSize(0.03);
0542 
0543     vector<clu_info> temp_sPH_inner_nocolumn_vec; temp_sPH_inner_nocolumn_vec.clear();
0544     vector<clu_info> temp_sPH_outer_nocolumn_vec; temp_sPH_outer_nocolumn_vec.clear();
0545     vector<vector<double>> temp_sPH_nocolumn_vec(2);
0546     vector<vector<double>> temp_sPH_nocolumn_rz_vec(2);
0547 
0548     TH2F * angle_correlation = new TH2F("","angle_correlation",361,0,361,361,0,361);
0549     angle_correlation -> SetStats(0);
0550     angle_correlation -> GetXaxis() -> SetTitle("Inner Phi [degree]");
0551     angle_correlation -> GetYaxis() -> SetTitle("Outer Phi [degree]");
0552 
0553     TH2F * angle_diff_DCA_dist = new TH2F("","angle_diff_DCA_dist",100,-1.5,1.5,100,-3.5,3.5);
0554     angle_diff_DCA_dist -> SetStats(0);
0555     angle_diff_DCA_dist -> GetXaxis() -> SetTitle("Inner - Outer [degree]");
0556     angle_diff_DCA_dist -> GetYaxis() -> SetTitle("DCA distance [mm]");
0557 
0558     TH1F * angle_diff = new TH1F("","angle_diff",100,0,3);
0559     angle_diff -> SetStats(0);
0560     angle_diff -> GetXaxis() -> SetTitle("|Inner - Outer| [degree]");
0561     angle_diff -> GetYaxis() -> SetTitle("Entry");
0562 
0563     TH1F * DCA_distance_1D = new TH1F("","DCA_distance_1D",100,-6,6);
0564     DCA_distance_1D -> SetStats(0);
0565     DCA_distance_1D -> GetXaxis() -> SetTitle("DCA distance");
0566     DCA_distance_1D -> GetYaxis() -> SetTitle("Entry");
0567 
0568     TH2F * angle_diff_inner_phi = new TH2F("","angle_diff_inner_phi",361,0,361,100,-1.5,1.5);
0569     angle_diff_inner_phi -> SetStats(0);
0570     angle_diff_inner_phi -> GetXaxis() -> SetTitle("Inner phi [degree]");
0571     angle_diff_inner_phi -> GetYaxis() -> SetTitle("Inner - Outer [degree]");
0572 
0573     TH2F * inner_pos_xy = new TH2F("","inner_pos_xy",360,-100,100,360,-100,100);
0574     inner_pos_xy -> SetStats(0);
0575     inner_pos_xy -> GetXaxis() -> SetTitle("X axis");
0576     inner_pos_xy -> GetYaxis() -> SetTitle("Y axis");
0577 
0578     TH2F * outer_pos_xy = new TH2F("","outer_pos_xy",360,-150,150,360,-150,150);
0579     outer_pos_xy -> SetStats(0);
0580     outer_pos_xy -> GetXaxis() -> SetTitle("X axis");
0581     outer_pos_xy -> GetYaxis() -> SetTitle("Y axis");
0582 
0583     TH2F * inner_outer_pos_xy = new TH2F("","inner_outer_pos_xy",360,-150,150,360,-150,150);
0584     inner_outer_pos_xy -> SetStats(0);
0585     inner_outer_pos_xy -> GetXaxis() -> SetTitle("X axis");
0586     inner_outer_pos_xy -> GetYaxis() -> SetTitle("Y axis");
0587 
0588     TH1F * z_pos_diff = new TH1F("","z_pos_diff",360,-150,150);
0589     z_pos_diff -> GetXaxis() -> SetTitle("Inner zpos - Outer zpos [mm]");
0590     z_pos_diff -> GetYaxis() -> SetTitle("Eentry");
0591 
0592     TH2F * z_pos_diff_angle_diff = new TH2F("","z_pos_diff_angle_diff",100,-25,25,200,-11,11);
0593     z_pos_diff_angle_diff -> SetStats(0);
0594     z_pos_diff_angle_diff -> GetXaxis() -> SetTitle("Inner zpos - Outer zpos [mm]");
0595     z_pos_diff_angle_diff -> GetYaxis() -> SetTitle("Inner phi - Outer phi [degree]");
0596 
0597     TH1F * Nhits_good = new TH1F("","Nhits_good",360,0,1000);
0598     Nhits_good -> GetXaxis() -> SetTitle("N hits in one event");
0599     Nhits_good -> GetYaxis() -> SetTitle("Eentry");
0600 
0601     TH1F * z_pos_inner = new TH1F("","z_pos_inner",200,-150,150);
0602     z_pos_inner -> GetXaxis() -> SetTitle("Inner zpos [mm]");
0603     z_pos_inner -> GetYaxis() -> SetTitle("Eentry");
0604 
0605     TH1F * z_pos_outer = new TH1F("","z_pos_outer",200,-150,150);
0606     z_pos_outer -> GetXaxis() -> SetTitle("Outer zpos [mm]");
0607     z_pos_outer -> GetYaxis() -> SetTitle("Eentry");
0608 
0609     TH2F * z_pos_inner_outer = new TH2F("","z_pos_inner_outer",100,-150,150, 100,-150,150);
0610     z_pos_inner_outer -> SetStats(0);
0611     z_pos_inner_outer -> GetXaxis() -> SetTitle("Inner zpos [mm]");
0612     z_pos_inner_outer -> GetYaxis() -> SetTitle("Outer pos [mm]");
0613 
0614     TH2F * DCA_point = new TH2F("","DCA_point",100,-10,10,100,-10,10);
0615     DCA_point -> SetStats(0);
0616     DCA_point -> GetXaxis() -> SetTitle("X pos [mm]");
0617     DCA_point -> GetYaxis() -> SetTitle("Y pos [mm]");
0618 
0619     TH2F * DCA_distance_inner_phi = new TH2F("","DCA_distance_inner_phi",100,0,360,100,-10,10);
0620     DCA_distance_inner_phi -> SetStats(0);
0621     DCA_distance_inner_phi -> GetXaxis() -> SetTitle("Inner phi [degree]");
0622     DCA_distance_inner_phi -> GetYaxis() -> SetTitle("DCA [mm]");
0623 
0624     TH2F * DCA_distance_outer_phi = new TH2F("","DCA_distance_outer_phi",100,0,360,100,-10,10);
0625     DCA_distance_outer_phi -> SetStats(0);
0626     DCA_distance_outer_phi -> GetXaxis() -> SetTitle("Outer phi [degree]");
0627     DCA_distance_outer_phi -> GetYaxis() -> SetTitle("DCA [mm]");
0628 
0629     TH1F * N_cluster_outer_pass = new TH1F("","N_cluster_outer_pass",100,0,100);
0630     N_cluster_outer_pass -> GetXaxis() -> SetTitle("N_cluster");
0631     N_cluster_outer_pass -> GetYaxis() -> SetTitle("Eentry");
0632 
0633     TH1F * N_cluster_inner_pass = new TH1F("","N_cluster_inner_pass",100,0,100);
0634     N_cluster_inner_pass -> GetXaxis() -> SetTitle("N_cluster");
0635     N_cluster_inner_pass -> GetYaxis() -> SetTitle("Eentry");
0636 
0637     TH2F * N_cluster_correlation = new TH2F("","N_cluster_correlation",100,0,500,100,0,500);
0638     N_cluster_correlation -> SetStats(0);
0639     N_cluster_correlation -> GetXaxis() -> SetTitle("inner N_cluster");
0640     N_cluster_correlation -> GetYaxis() -> SetTitle("Outer N_cluster");
0641 
0642     TH1F * temp_event_zvtx = new TH1F("","Z vertex dist",125,zvtx_hist_l,zvtx_hist_r);
0643     temp_event_zvtx -> GetXaxis() -> SetTitle("Z vertex position [mm]");
0644     temp_event_zvtx -> GetYaxis() -> SetTitle("Entry");
0645     vector<float> temp_event_zvtx_vec; temp_event_zvtx_vec.clear();
0646     vector<float> temp_event_zvtx_info; temp_event_zvtx_info.clear();
0647     TLine * effi_sig_range_line = new TLine();
0648     effi_sig_range_line -> SetLineWidth(3);
0649     effi_sig_range_line -> SetLineColor(TColor::GetColor("#A08144"));
0650     effi_sig_range_line -> SetLineStyle(2);
0651     TF1 * gaus_fit = new TF1("",gaus_func,-10,10,4);
0652     gaus_fit -> SetLineColor(2);
0653 
0654 
0655         // note : par[0] : size of gaus1
0656     // note : par[1] : mean of gaus1
0657     // note : par[2] : width of gaus1
0658     // note : par[3] : offset of gaus1 
0659 
0660     // note : par[4] : size of gaus2
0661     // note : par[5] : mean of gaus2
0662     // note : par[6] : width of gaus2
0663 
0664     TF1 * double_gaus_fit = new TF1("",double_gaus_func,-10,10,7);
0665     double_gaus_fit -> SetLineColor(3);
0666     double_gaus_fit -> SetParNames("G1 size", "G1 mean", "G1 width", "Offset", "G2 size", "G2 mean", "G2 width");
0667     TF1 * gaus_1 = new TF1("",gaus_func,-10,10,4);
0668     gaus_1 -> SetLineColor(6);
0669     gaus_1 -> SetLineStyle(7);
0670     TF1 * gaus_2 = new TF1("",gaus_func,-10,10,4);
0671     gaus_2 -> SetLineColor(6);
0672     gaus_2 -> SetLineStyle(7);
0673 
0674     double N_good_event = 0;
0675 
0676     TH2F * Good_inner_outer_pos_xy_nzB = new TH2F("","Good_inner_outer_pos_xy_nzB",360,-150,150,360,-150,150);
0677     Good_inner_outer_pos_xy_nzB -> SetStats(0);
0678     Good_inner_outer_pos_xy_nzB -> GetXaxis() -> SetTitle("X axis");
0679     Good_inner_outer_pos_xy_nzB -> GetYaxis() -> SetTitle("Y axis");
0680 
0681     TH2F * Good_inner_outer_pos_xy_nzA = new TH2F("","Good_inner_outer_pos_xy_nzA",360,-150,150,360,-150,150);
0682     Good_inner_outer_pos_xy_nzA -> SetStats(0);
0683     Good_inner_outer_pos_xy_nzA -> GetXaxis() -> SetTitle("X axis");
0684     Good_inner_outer_pos_xy_nzA -> GetYaxis() -> SetTitle("Y axis");
0685 
0686     TH2F * Good_inner_outer_pos_xy_pzA = new TH2F("","Good_inner_outer_pos_xy_pzA",360,-150,150,360,-150,150);
0687     Good_inner_outer_pos_xy_pzA -> SetStats(0);
0688     Good_inner_outer_pos_xy_pzA -> GetXaxis() -> SetTitle("X axis");
0689     Good_inner_outer_pos_xy_pzA -> GetYaxis() -> SetTitle("Y axis");
0690 
0691     TH2F * Good_inner_outer_pos_xy_pzB = new TH2F("","Good_inner_outer_pos_xy_pzB",360,-150,150,360,-150,150);
0692     Good_inner_outer_pos_xy_pzB -> SetStats(0);
0693     Good_inner_outer_pos_xy_pzB -> GetXaxis() -> SetTitle("X axis");
0694     Good_inner_outer_pos_xy_pzB -> GetYaxis() -> SetTitle("Y axis");
0695 
0696     TH2F * Good_track_space = new TH2F("","Good_track_space",200,-300,300,200,-300,300);
0697     Good_track_space -> SetStats(0);
0698     Good_track_space -> GetXaxis() -> SetTitle("X axis");
0699     Good_track_space -> GetYaxis() -> SetTitle("Y axis");
0700 
0701     // dNdeta_hist -> GetXaxis() -> SetLimits(-10,10);
0702     // dNdeta_hist -> GetXaxis() -> SetNdivisions  (505);
0703 
0704     TF1 * zvtx_finder = new TF1("zvtx_finder","pol0",-1,3000); 
0705 
0706     
0707     vector<vector<double>> good_track_xy_vec; good_track_xy_vec.clear();
0708     vector<vector<double>> good_track_rz_vec; good_track_rz_vec.clear();
0709     vector<vector<double>> good_comb_rz_vec; good_comb_rz_vec.clear();
0710     vector<vector<double>> good_comb_xy_vec; good_comb_xy_vec.clear();
0711     vector<vector<double>> good_comb_phi_vec; good_comb_phi_vec.clear();
0712     vector<vector<double>> good_tracklet_rz; good_tracklet_rz.clear();
0713     TLine * track_line = new TLine();
0714     track_line -> SetLineWidth(1);
0715     track_line -> SetLineColorAlpha(38,0.5);
0716 
0717     TLine * coord_line = new TLine();
0718     coord_line -> SetLineWidth(1);
0719     coord_line -> SetLineColor(16);
0720     coord_line -> SetLineStyle(2);
0721 
0722 
0723     vector<float> avg_event_zvtx_vec; avg_event_zvtx_vec.clear();
0724     TH1F * avg_event_zvtx = new TH1F("","avg_event_zvtx",125,zvtx_hist_l,zvtx_hist_r);
0725     // avg_event_zvtx -> SetMarkerStyle(20);
0726     // avg_event_zvtx -> SetMarkerSize(0.8);
0727     // avg_event_zvtx -> SetMarkerColor(TColor::GetColor("#1A3947"));
0728     avg_event_zvtx -> SetLineColor(TColor::GetColor("#1A3947"));
0729     avg_event_zvtx -> SetLineWidth(2);
0730     avg_event_zvtx -> GetYaxis() -> SetTitle("Entry");
0731     avg_event_zvtx -> GetXaxis() -> SetTitle("Z vertex position [mm]");
0732     avg_event_zvtx -> GetYaxis() -> SetRangeUser(0,50);
0733     avg_event_zvtx -> SetTitleSize(0.06, "X");
0734     avg_event_zvtx -> SetTitleSize(0.06, "Y");
0735     avg_event_zvtx -> GetXaxis() -> SetTitleOffset (0.82);
0736     avg_event_zvtx -> GetYaxis() -> SetTitleOffset (1.1);
0737     avg_event_zvtx -> GetXaxis() -> CenterTitle(true);
0738     avg_event_zvtx -> GetYaxis() -> CenterTitle(true);
0739     avg_event_zvtx -> GetXaxis() -> SetNdivisions  (505);
0740 
0741     TH1F * zvtx_evt_width = new TH1F("","zvtx_evt_width",150,0,800);
0742     zvtx_evt_width -> GetXaxis() -> SetTitle(" mm ");
0743     zvtx_evt_width -> GetYaxis() -> SetTitle("entry");
0744 
0745     TH2F * zvtx_evt_fitError_corre = new TH2F("","zvtx_evt_fitError_corre",200,0,10000,200,0,20);
0746     zvtx_evt_fitError_corre -> GetXaxis() -> SetTitle(" # of clusters ");
0747     zvtx_evt_fitError_corre -> GetYaxis() -> SetTitle(" #pm mm ");
0748 
0749     TH2F * zvtx_evt_width_corre = new TH2F("","zvtx_evt_width_corre",200,0,10000,200,0,300);
0750     zvtx_evt_width_corre -> GetXaxis() -> SetTitle(" # of clusters ");
0751     zvtx_evt_width_corre -> GetYaxis() -> SetTitle(" mm ");
0752 
0753     TH2F * zvtx_evt_nclu_corre = new TH2F("","zvtx_evt_nclu_corre",200,0,10000,200,-500,500);
0754     zvtx_evt_nclu_corre -> GetXaxis() -> SetTitle(" # of clusters ");
0755     zvtx_evt_nclu_corre -> GetYaxis() -> SetTitle(" zvtx [mm] ");
0756     zvtx_evt_nclu_corre -> GetXaxis() -> SetNdivisions  (505);
0757 
0758     TH1F * width_density = new TH1F("","width_density",200,0,1); // note : N good hits / width
0759     width_density -> GetXaxis() -> SetTitle(" N good zvtx / width ");
0760     width_density -> GetYaxis() -> SetTitle(" Entry ");
0761     
0762     int inner_1_check = 0; int inner_2_check = 0; int inner_3_check = 0; int inner_4_check = 0;
0763     int outer_1_check = 0; int outer_2_check = 0; int outer_3_check = 0; int outer_4_check = 0;
0764     vector<int> used_outer_check(temp_sPH_outer_nocolumn_vec.size(),0);
0765     vector<float> N_comb; vector<float> N_comb_e; vector<float> z_mid; vector<float> z_range;
0766     vector<double> effi_N_comb; vector<double> effi_z_mid; vector<double> effi_N_comb_e; vector<double> effi_z_range;
0767 
0768     int N_event_pass_number = 0;
0769     int greatest_N_clu = 0;
0770     
0771     if (draw_event_display) c2 -> Print(Form("%s/folder_%s_advanced/temp_event_display.pdf(",mother_folder_directory.c_str(),file_name.c_str()));
0772 
0773     for (int event_i = 0; event_i < N_event; event_i++)
0774     {
0775         if (event_i % 1000 == 0) cout<<"code running... "<<event_i<<endl;
0776 
0777         // cout<<"========================= test : "<<event_i<<" ========================="<<endl;
0778 
0779         tree -> GetEntry(event_i);
0780         unsigned int length = column_vec -> size();
0781 
0782         if (event_i == 13) cout<<"test, eID : "<<event_i<<" Nhits "<<N_hits<<endl;
0783 
0784         if (N_hits > Nhit_cut) {continue;}
0785         if (N_hits < Nhit_cutl) {continue;}
0786 
0787         N_event_pass_number += 1;
0788 
0789         if (N_cluster_inner == 0 || N_cluster_outer == 0) {continue;}
0790         if (N_cluster_inner == -1 || N_cluster_outer == -1) {continue;}
0791         if ((N_cluster_inner + N_cluster_outer) < zvtx_cal_require) {continue;}
0792         if (N_cluster_inner < 10) {continue;}
0793         if (N_cluster_outer < 10) {continue;}
0794         
0795         // cout<<"test point 1"<<endl;
0796         // note : apply some selection to remove the hot channels
0797         // note : and make the inner_clu_vec and outer_clu_vec
0798         for (int clu_i = 0; clu_i < length; clu_i++)
0799         {
0800             if (size_vec -> at(clu_i) > clu_size_cut) continue; 
0801             // if (size_vec -> at(clu_i) < 2) continue;
0802             if (sum_adc_conv_vec -> at(clu_i) < clu_sum_adc_cut) continue;
0803             // if (z_vec -> at(clu_i) < 0) continue;
0804             
0805             // note : inner
0806             // if (layer_vec -> at(clu_i) == 0 && x_vec -> at(clu_i) < -75 && x_vec -> at(clu_i) > -80 && y_vec -> at(clu_i) > 7.5 && y_vec -> at(clu_i) < 12.5 ) continue;
0807             // // if (layer_vec -> at(clu_i) == 0 && x_vec -> at(clu_i) > 35 && x_vec -> at(clu_i) < 40 && y_vec -> at(clu_i) > 65 && y_vec -> at(clu_i) < 70 ) continue;
0808             // if (layer_vec -> at(clu_i) == 0 && phi_vec -> at(clu_i) > 295 && phi_vec -> at(clu_i) < 302) continue;
0809             // if (layer_vec -> at(clu_i) == 0 && phi_vec -> at(clu_i) > 210 && phi_vec -> at(clu_i) < 213) continue;
0810             // if (layer_vec -> at(clu_i) == 0 && phi_vec -> at(clu_i) > 55 && phi_vec -> at(clu_i) < 65) continue;
0811             // if (layer_vec -> at(clu_i) == 0 && phi_vec -> at(clu_i) > 348 && phi_vec -> at(clu_i) < 353) continue;
0812             // if (layer_vec -> at(clu_i) == 0 && phi_vec -> at(clu_i) > 265 && phi_vec -> at(clu_i) < 270) continue;
0813 
0814             // note : outer
0815             // if (layer_vec -> at(clu_i) == 1 && x_vec -> at(clu_i) < -70 && x_vec -> at(clu_i) > -75 && y_vec -> at(clu_i) > 70 && y_vec -> at(clu_i) < 80 ) continue;
0816             // // if (layer_vec -> at(clu_i) == 1 && x_vec -> at(clu_i) > 70 && x_vec -> at(clu_i) < 83 && y_vec -> at(clu_i) > 50 && y_vec -> at(clu_i) < 65 ) continue;
0817             // // if (layer_vec -> at(clu_i) == 1 && x_vec -> at(clu_i) > 70 && x_vec -> at(clu_i) < 83 && y_vec -> at(clu_i) > 63 && y_vec -> at(clu_i) < 75 ) continue;
0818             // if (layer_vec -> at(clu_i) == 1 && x_vec -> at(clu_i) < -70 && x_vec -> at(clu_i) > -75 && y_vec -> at(clu_i) < -70 && y_vec -> at(clu_i) > -75 ) continue;
0819             // if (layer_vec -> at(clu_i) == 1 && phi_vec -> at(clu_i) > 335 && phi_vec -> at(clu_i) < 340) continue;
0820             // if (layer_vec -> at(clu_i) == 1 && phi_vec -> at(clu_i) > 105 && phi_vec -> at(clu_i) < 115) continue;
0821             // if (layer_vec -> at(clu_i) == 1 && phi_vec -> at(clu_i) > 25 && phi_vec -> at(clu_i) < 47) continue; // todo : for the "new_DAC_Scan_0722/AllServer/DAC2"
0822 
0823 
0824             temp_sPH_nocolumn_vec[0].push_back( (phi_vec -> at(clu_i) > 90 && phi_vec -> at(clu_i) < 270 ) ? x_vec -> at(clu_i) + temp_X_align : x_vec -> at(clu_i) );
0825             temp_sPH_nocolumn_vec[1].push_back( (phi_vec -> at(clu_i) > 90 && phi_vec -> at(clu_i) < 270 ) ? y_vec -> at(clu_i) + temp_Y_align : y_vec -> at(clu_i) );
0826             
0827             double clu_radius = get_radius(
0828                 (phi_vec -> at(clu_i) > 90 && phi_vec -> at(clu_i) < 270 ) ? x_vec -> at(clu_i) + temp_X_align : x_vec -> at(clu_i), 
0829                 (phi_vec -> at(clu_i) > 90 && phi_vec -> at(clu_i) < 270 ) ? y_vec -> at(clu_i) + temp_Y_align : y_vec -> at(clu_i)
0830             );
0831             temp_sPH_nocolumn_rz_vec[0].push_back(z_vec -> at(clu_i));
0832             temp_sPH_nocolumn_rz_vec[1].push_back( ( phi_vec -> at(clu_i) > 180 ) ? clu_radius * -1 : clu_radius );
0833             
0834 
0835             if (layer_vec -> at(clu_i) == 0) // note : inner
0836                 temp_sPH_inner_nocolumn_vec.push_back({
0837                     column_vec -> at(clu_i), 
0838                     avg_chan_vec -> at(clu_i), 
0839                     sum_adc_vec -> at(clu_i), 
0840                     sum_adc_conv_vec -> at(clu_i), 
0841                     size_vec -> at(clu_i), 
0842                     (phi_vec -> at(clu_i) > 90 && phi_vec -> at(clu_i) < 270 ) ? x_vec -> at(clu_i) + temp_X_align : x_vec -> at(clu_i), 
0843                     (phi_vec -> at(clu_i) > 90 && phi_vec -> at(clu_i) < 270 ) ? y_vec -> at(clu_i) + temp_Y_align : y_vec -> at(clu_i), 
0844                     z_vec -> at(clu_i), 
0845                     layer_vec -> at(clu_i), 
0846                     phi_vec -> at(clu_i)
0847                 });
0848             
0849             if (layer_vec -> at(clu_i) == 1) // note : outer
0850                 temp_sPH_outer_nocolumn_vec.push_back({
0851                     column_vec -> at(clu_i), 
0852                     avg_chan_vec -> at(clu_i), 
0853                     sum_adc_vec -> at(clu_i), 
0854                     sum_adc_conv_vec -> at(clu_i), 
0855                     size_vec -> at(clu_i), 
0856                     (phi_vec -> at(clu_i) > 90 && phi_vec -> at(clu_i) < 270 ) ? x_vec -> at(clu_i) + temp_X_align : x_vec -> at(clu_i), 
0857                     (phi_vec -> at(clu_i) > 90 && phi_vec -> at(clu_i) < 270 ) ? y_vec -> at(clu_i) + temp_Y_align : y_vec -> at(clu_i), 
0858                     z_vec -> at(clu_i), 
0859                     layer_vec -> at(clu_i), 
0860                     phi_vec -> at(clu_i)
0861                 });            
0862         }
0863         // cout<<"test point 2"<<endl;
0864 
0865         inner_1_check = 0;
0866         inner_2_check = 0;
0867         inner_3_check = 0;
0868         inner_4_check = 0;
0869         for (int inner_i = 0; inner_i < temp_sPH_inner_nocolumn_vec.size(); inner_i++) {
0870             if (temp_sPH_inner_nocolumn_vec[inner_i].phi >= 0 && temp_sPH_inner_nocolumn_vec[inner_i].phi < 90)    inner_1_check = 1;
0871             if (temp_sPH_inner_nocolumn_vec[inner_i].phi >= 90 && temp_sPH_inner_nocolumn_vec[inner_i].phi < 180)  inner_2_check = 1;
0872             if (temp_sPH_inner_nocolumn_vec[inner_i].phi >= 180 && temp_sPH_inner_nocolumn_vec[inner_i].phi < 270) inner_3_check = 1;
0873             if (temp_sPH_inner_nocolumn_vec[inner_i].phi >= 270 && temp_sPH_inner_nocolumn_vec[inner_i].phi < 360) inner_4_check = 1;
0874 
0875             if ( (inner_1_check + inner_2_check + inner_3_check + inner_4_check) == 4 ) break;
0876         }
0877 
0878         outer_1_check = 0;
0879         outer_2_check = 0;
0880         outer_3_check = 0;
0881         outer_4_check = 0;
0882         for (int outer_i = 0; outer_i < temp_sPH_outer_nocolumn_vec.size(); outer_i++) {
0883             if (temp_sPH_outer_nocolumn_vec[outer_i].phi >= 0 && temp_sPH_outer_nocolumn_vec[outer_i].phi < 90)    outer_1_check = 1;
0884             if (temp_sPH_outer_nocolumn_vec[outer_i].phi >= 90 && temp_sPH_outer_nocolumn_vec[outer_i].phi < 180)  outer_2_check = 1;
0885             if (temp_sPH_outer_nocolumn_vec[outer_i].phi >= 180 && temp_sPH_outer_nocolumn_vec[outer_i].phi < 270) outer_3_check = 1;
0886             if (temp_sPH_outer_nocolumn_vec[outer_i].phi >= 270 && temp_sPH_outer_nocolumn_vec[outer_i].phi < 360) outer_4_check = 1;
0887 
0888             if ( (outer_1_check + outer_2_check + outer_3_check + outer_4_check) == 4 ) break;
0889         }
0890 
0891         // cout<<"test point 3"<<endl;
0892 
0893         N_cluster_outer_pass -> Fill(temp_sPH_outer_nocolumn_vec.size());
0894         N_cluster_inner_pass -> Fill(temp_sPH_inner_nocolumn_vec.size());
0895         N_cluster_correlation -> Fill( temp_sPH_inner_nocolumn_vec.size(), temp_sPH_outer_nocolumn_vec.size() );
0896 
0897         if ( (temp_sPH_inner_nocolumn_vec.size() + temp_sPH_outer_nocolumn_vec.size()) > greatest_N_clu) {greatest_N_clu = (temp_sPH_inner_nocolumn_vec.size() + temp_sPH_outer_nocolumn_vec.size());}
0898 
0899         if ((temp_sPH_inner_nocolumn_vec.size() + temp_sPH_outer_nocolumn_vec.size()) > N_clu_cut || (temp_sPH_inner_nocolumn_vec.size() + temp_sPH_outer_nocolumn_vec.size()) < N_clu_cutl)
0900         {
0901             temp_event_zvtx_info = {-1000,-1000,-1000};
0902             temp_event_zvtx_vec.clear();
0903             temp_event_zvtx -> Reset("ICESM");
0904             good_track_xy_vec.clear();
0905             good_track_rz_vec.clear();
0906             good_comb_rz_vec.clear();
0907             good_comb_xy_vec.clear();
0908             good_comb_phi_vec.clear();
0909             temp_sPH_nocolumn_rz_vec.clear(); temp_sPH_nocolumn_rz_vec = vector<vector<double>>(2);
0910             temp_sPH_nocolumn_vec.clear(); temp_sPH_nocolumn_vec = vector<vector<double>>(2);
0911             temp_sPH_inner_nocolumn_vec.clear();
0912             temp_sPH_outer_nocolumn_vec.clear();
0913             continue;
0914         }
0915 
0916         if ( (inner_1_check + inner_2_check + inner_3_check + inner_4_check + outer_1_check + outer_2_check + outer_3_check + outer_4_check) != 8 )
0917         {
0918             cout<<"some quater of INTT doens't work !! eID : "<<event_i<<endl;
0919             temp_event_zvtx_info = {-1000,-1000,-1000};
0920             temp_event_zvtx_vec.clear();
0921             temp_event_zvtx -> Reset("ICESM");
0922             good_track_xy_vec.clear();
0923             good_track_rz_vec.clear();
0924             good_comb_rz_vec.clear();
0925             good_comb_xy_vec.clear();
0926             good_comb_phi_vec.clear();
0927             temp_sPH_nocolumn_rz_vec.clear(); temp_sPH_nocolumn_rz_vec = vector<vector<double>>(2);
0928             temp_sPH_nocolumn_vec.clear(); temp_sPH_nocolumn_vec = vector<vector<double>>(2);
0929             temp_sPH_inner_nocolumn_vec.clear();
0930             temp_sPH_outer_nocolumn_vec.clear();
0931             continue;
0932         }
0933         
0934         N_comb.clear();
0935         N_comb_e.clear();
0936         // z_mid.clear(); 
0937         // z_range.clear();
0938         
0939 
0940         // note : try to make sure that the clusters not to be used twice or more 
0941         // used_outer_check.clear();
0942         // used_outer_check = vector<int>(temp_sPH_outer_nocolumn_vec.size(),0);
0943 
0944         // cout<<"test point 4 di loop start"<<endl;
0945 
0946         for ( int inner_i = 0; inner_i < temp_sPH_inner_nocolumn_vec.size(); inner_i++ )
0947         {
0948             
0949             for ( int outer_i = 0; outer_i < temp_sPH_outer_nocolumn_vec.size(); outer_i++ )
0950             {
0951                 // bool DCA_tag = false;
0952                 // if (used_outer_check[outer_i] == 1) continue; // note : this outer cluster was already used, skip the trial of this combination
0953                 
0954                 vector<double> DCA_info_vec = calculateDistanceAndClosestPoint(
0955                     temp_sPH_inner_nocolumn_vec[inner_i].x, temp_sPH_inner_nocolumn_vec[inner_i].y,
0956                     temp_sPH_outer_nocolumn_vec[outer_i].x, temp_sPH_outer_nocolumn_vec[outer_i].y,
0957                     beam_origin.first, beam_origin.second
0958                 );
0959 
0960                 double DCA_sign = calculateAngleBetweenVectors(
0961                     temp_sPH_outer_nocolumn_vec[outer_i].x, temp_sPH_outer_nocolumn_vec[outer_i].y,
0962                     temp_sPH_inner_nocolumn_vec[inner_i].x, temp_sPH_inner_nocolumn_vec[inner_i].y,
0963                     beam_origin.first, beam_origin.second
0964                 );
0965 
0966                 angle_correlation -> Fill(temp_sPH_inner_nocolumn_vec[inner_i].phi,temp_sPH_outer_nocolumn_vec[outer_i].phi);
0967                 angle_diff -> Fill(fabs(temp_sPH_inner_nocolumn_vec[inner_i].phi - temp_sPH_outer_nocolumn_vec[outer_i].phi));
0968                 // angle_diff -> Fill( temp_sPH_inner_nocolumn_vec[inner_i].phi - temp_sPH_outer_nocolumn_vec[outer_i].phi );
0969 
0970                 if (DCA_info_vec[0] != fabs(DCA_sign) && fabs( DCA_info_vec[0] - fabs(DCA_sign) ) > 0.1 ){
0971                     cout<<"different DCA : "<<DCA_info_vec[0]<<" "<<DCA_sign<<" diff : "<<DCA_info_vec[0] - fabs(DCA_sign)<<endl;}
0972 
0973                 if (fabs(temp_sPH_inner_nocolumn_vec[inner_i].phi - temp_sPH_outer_nocolumn_vec[outer_i].phi) < phi_diff_cut)
0974                 {
0975                     // if (DCA_info_vec[0] < DCA_cut){
0976 
0977                     //     used_outer_check[outer_i] = 1; //note : this outer cluster was already used!
0978 
0979                     //     pair<double,double> z_range_info = Get_possible_zvtx( 
0980                     //         get_radius(beam_origin.first,beam_origin.second), 
0981                     //         {get_radius(temp_sPH_inner_nocolumn_vec[inner_i].x, temp_sPH_inner_nocolumn_vec[inner_i].y), temp_sPH_inner_nocolumn_vec[inner_i].z}, // note : unsign radius
0982                     //         {get_radius(temp_sPH_outer_nocolumn_vec[outer_i].x, temp_sPH_outer_nocolumn_vec[outer_i].y), temp_sPH_outer_nocolumn_vec[outer_i].z}  // note : unsign radius
0983                     //     );
0984                         
0985                     //     N_comb.push_back(inner_i);
0986                     //     N_comb_e.push_back(0);
0987                     //     z_mid.push_back(z_range_info.first);
0988                     //     z_range.push_back(z_range_info.second);
0989 
0990                     //     // DCA_tag = true;
0991                     // }
0992 
0993                     angle_diff_inner_phi -> Fill(temp_sPH_inner_nocolumn_vec[inner_i].phi, temp_sPH_inner_nocolumn_vec[inner_i].phi - temp_sPH_outer_nocolumn_vec[outer_i].phi);
0994 
0995                     if (temp_sPH_inner_nocolumn_vec[inner_i].phi > 270)
0996                         angle_diff_DCA_dist -> Fill(temp_sPH_inner_nocolumn_vec[inner_i].phi - temp_sPH_outer_nocolumn_vec[outer_i].phi, DCA_sign);
0997 
0998                     DCA_point -> Fill( DCA_info_vec[1], DCA_info_vec[2] );
0999                     // angle_correlation -> Fill(temp_sPH_inner_nocolumn_vec[inner_i].phi,temp_sPH_outer_nocolumn_vec[outer_i].phi);
1000                     z_pos_diff -> Fill( temp_sPH_inner_nocolumn_vec[inner_i].z - temp_sPH_outer_nocolumn_vec[outer_i].z );
1001                     z_pos_diff_angle_diff -> Fill( temp_sPH_inner_nocolumn_vec[inner_i].z - temp_sPH_outer_nocolumn_vec[outer_i].z, temp_sPH_inner_nocolumn_vec[inner_i].phi - temp_sPH_outer_nocolumn_vec[outer_i].phi );
1002                     Nhits_good -> Fill(N_hits);
1003                     z_pos_inner -> Fill(temp_sPH_inner_nocolumn_vec[inner_i].z);
1004                     z_pos_outer -> Fill(temp_sPH_outer_nocolumn_vec[outer_i].z);
1005                     z_pos_inner_outer -> Fill(temp_sPH_inner_nocolumn_vec[inner_i].z, temp_sPH_outer_nocolumn_vec[outer_i].z);
1006                     // DCA_distance_inner_phi -> Fill(temp_sPH_inner_nocolumn_vec[inner_i].phi, (temp_sPH_inner_nocolumn_vec[inner_i].phi > 90 && temp_sPH_inner_nocolumn_vec[inner_i].phi < 270) ? DCA_sign * -1 : DCA_sign );
1007                     // DCA_distance_outer_phi -> Fill(temp_sPH_outer_nocolumn_vec[outer_i].phi, (temp_sPH_outer_nocolumn_vec[outer_i].phi > 90 && temp_sPH_outer_nocolumn_vec[outer_i].phi < 270) ? DCA_sign * -1 : DCA_sign );
1008                     DCA_distance_inner_phi -> Fill(temp_sPH_inner_nocolumn_vec[inner_i].phi, DCA_sign );
1009                     DCA_distance_outer_phi -> Fill(temp_sPH_outer_nocolumn_vec[outer_i].phi, DCA_sign );
1010                     DCA_distance_1D -> Fill(DCA_sign);
1011 
1012                     // if(DCA_tag == true) break; // note : since this combination (one inner cluster, one outer cluster) satisfied the reuqiremet, no reason to ask this inner cluster try with other outer clusters
1013 
1014                     // cout<<"good comb : "<<fabs(temp_sPH_inner_nocolumn_vec[inner_i].phi - temp_sPH_outer_nocolumn_vec[outer_i].phi)<<" radius in : "<<get_radius(temp_sPH_inner_nocolumn_vec[inner_i].x, temp_sPH_inner_nocolumn_vec[inner_i].y)<<" radius out : "<<get_radius(temp_sPH_outer_nocolumn_vec[outer_i].x, temp_sPH_outer_nocolumn_vec[outer_i].y)<<endl;
1015                 } // note : end of if 
1016                     
1017 
1018             } // note : end of outer loop
1019         } // note : end of inner loop
1020 
1021         // cout<<"test point 5 di loop end"<<endl;
1022 
1023         // cout<<"test tag 0"<<endl;
1024         // TGraphErrors * z_range_gr;
1025         // effi_N_comb.clear();
1026         // effi_z_mid.clear();
1027         // effi_N_comb_e.clear();
1028         // effi_z_range.clear();
1029         // // cout<<"test tag 1"<<endl;
1030         // // cout<<"test, N_comb size : "<<N_comb.size()<<endl;
1031         // if (N_comb.size() > zvtx_cal_require)
1032         // {   
1033         //     temp_event_zvtx_info = sigmaEff_avg(z_mid,Integrate_portion);
1034             
1035         //     for (int track_i = 0; track_i < N_comb.size(); track_i++) {
1036         //         if (temp_event_zvtx_info[1] <= z_mid[track_i] && z_mid[track_i] <= temp_event_zvtx_info[2]) {
1037         //             effi_N_comb.push_back(N_comb[track_i]);
1038         //             effi_z_mid.push_back(z_mid[track_i]);
1039         //             effi_N_comb_e.push_back(N_comb_e[track_i]);
1040         //             effi_z_range.push_back(z_range[track_i]);
1041         //         }
1042         //     }
1043 
1044         //     z_range_gr = new TGraphErrors(effi_N_comb.size(),&effi_N_comb[0],&effi_z_mid[0],&effi_N_comb_e[0],&effi_z_range[0]);
1045         //     // z_range_gr = new TGraph(effi_N_comb.size(),&effi_N_comb[0],&effi_z_mid[0]);
1046         //     z_range_gr -> Fit(zvtx_finder,"NQ","",0,N_comb[N_comb.size() - 1] * 0.7); // note : not fit all the combination
1047             
1048             
1049         //     // avg_event_zvtx -> Fill(zvtx_finder -> GetParameter(0));
1050         //     zvtx_evt_width -> Fill(fabs( zvtx_finder -> GetParError(0)));
1051         //     zvtx_evt_fitError_corre -> Fill(temp_sPH_inner_nocolumn_vec.size() + temp_sPH_outer_nocolumn_vec.size(), fabs( zvtx_finder -> GetParError(0)));
1052         //     zvtx_evt_width_corre -> Fill(temp_sPH_inner_nocolumn_vec.size() + temp_sPH_outer_nocolumn_vec.size(), fabs(temp_event_zvtx_info[2] - temp_event_zvtx_info[1]));
1053         //     width_density -> Fill( effi_N_comb.size() / fabs(temp_event_zvtx_info[2] - temp_event_zvtx_info[1]) );
1054         //     // cout<<"test, width density : "<<( effi_N_comb.size() / fabs(temp_event_zvtx_info[2] - temp_event_zvtx_info[1]) )<<endl;
1055         //     if ( ( effi_N_comb.size() / fabs(temp_event_zvtx_info[2] - temp_event_zvtx_info[1]) ) > 0.0 ){ // todo : the density may have to be fine tuned
1056         //         zvtx_evt_nclu_corre -> Fill(temp_sPH_inner_nocolumn_vec.size() + temp_sPH_outer_nocolumn_vec.size(), zvtx_finder -> GetParameter(0));
1057         //         avg_event_zvtx -> Fill(zvtx_finder -> GetParameter(0));
1058         //         avg_event_zvtx_vec.push_back(zvtx_finder -> GetParameter(0));
1059         //     }
1060             
1061         //     out_eID = event_i;
1062         //     N_cluster_inner_out = temp_sPH_inner_nocolumn_vec.size();
1063         //     N_cluster_outer_out = temp_sPH_outer_nocolumn_vec.size();
1064         //     out_zvtx = zvtx_finder -> GetParameter(0);
1065         //     out_zvtxE = zvtx_finder -> GetParError(0);
1066         //     out_rangeL = temp_event_zvtx_info[1];
1067         //     out_rangeR = temp_event_zvtx_info[2];
1068         //     out_N_good = effi_N_comb.size();
1069         //     out_width_density = effi_N_comb.size() / fabs(temp_event_zvtx_info[2] - temp_event_zvtx_info[1]);
1070 
1071         //     z_range_gr -> Delete();
1072         // } // note : if N good tracks in xy found > certain value
1073         // cout<<"test tag 2"<<endl;
1074         
1075         // cout<<"test point 6"<<endl;
1076 
1077         if ( draw_event_display == true && N_comb.size() > zvtx_cal_require)
1078         {   
1079             TGraph * temp_event_xy = new TGraph(temp_sPH_nocolumn_vec[0].size(),&temp_sPH_nocolumn_vec[0][0],&temp_sPH_nocolumn_vec[1][0]);
1080             temp_event_xy -> SetTitle("INTT event display X-Y plane");
1081             temp_event_xy -> GetXaxis() -> SetLimits(-150,150);
1082             temp_event_xy -> GetYaxis() -> SetRangeUser(-150,150);
1083             temp_event_xy -> GetXaxis() -> SetTitle("X [mm]");
1084             temp_event_xy -> GetYaxis() -> SetTitle("Y [mm]");
1085             temp_event_xy -> SetMarkerStyle(20);
1086             temp_event_xy -> SetMarkerColor(2);
1087             temp_event_xy -> SetMarkerSize(1);
1088             TGraph * temp_event_rz = new TGraph(temp_sPH_nocolumn_rz_vec[0].size(),&temp_sPH_nocolumn_rz_vec[0][0],&temp_sPH_nocolumn_rz_vec[1][0]);
1089             temp_event_rz -> SetTitle("INTT event display r-Z plane");
1090             temp_event_rz -> GetXaxis() -> SetLimits(-500,500);
1091             temp_event_rz -> GetYaxis() -> SetRangeUser(-150,150);
1092             temp_event_rz -> GetXaxis() -> SetTitle("Z [mm]");
1093             temp_event_rz -> GetYaxis() -> SetTitle("Radius [mm]");
1094             temp_event_rz -> SetMarkerStyle(20);
1095             temp_event_rz -> SetMarkerColor(2);
1096             temp_event_rz -> SetMarkerSize(1);
1097 
1098             pad_xy -> cd();
1099             temp_bkg(pad_xy, conversion_mode, peek, beam_origin, ch_pos_DB);
1100             temp_event_xy -> Draw("p same");
1101             for (int track_i = 0; track_i < good_track_xy_vec.size(); track_i++){
1102                 track_line -> DrawLine(good_track_xy_vec[track_i][0],good_track_xy_vec[track_i][1],good_track_xy_vec[track_i][2],good_track_xy_vec[track_i][3]);
1103             }
1104             track_line -> Draw("l same");
1105             draw_text -> DrawLatex(0.2, 0.85, Form("eID : %i, Total event hit : %i, innter Ncluster : %i, outer Ncluster : %i",event_i,N_hits,temp_sPH_inner_nocolumn_vec.size(),temp_sPH_outer_nocolumn_vec.size()));
1106         
1107             pad_rz -> cd();
1108             temp_event_rz -> Draw("ap");    
1109             // effi_sig_range_line -> DrawLine(temp_event_zvtx_info[0],-150,temp_event_zvtx_info[0],150);
1110             coord_line -> DrawLine(0,-150,0,150);
1111             coord_line -> DrawLine(-500,0,500,0);
1112             for (int track_i = 0; track_i < good_track_rz_vec.size(); track_i++){
1113                 track_line -> DrawLine(good_track_rz_vec[track_i][0],good_track_rz_vec[track_i][1],good_track_rz_vec[track_i][2],good_track_rz_vec[track_i][3]);
1114             }
1115             draw_text -> DrawLatex(0.2, 0.85, Form("Negative radius : Clu_{outer} > 180^{0}"));
1116             // draw_text -> DrawLatex(0.2, 0.81, Form("EffiSig avg : %.2f mm",temp_event_zvtx_info[0]));
1117 
1118             // cout<<"test tag 2-5"<<endl;    
1119             pad_z -> cd();
1120             // TGraphErrors * z_range_gr_draw = new TGraphErrors(N_comb.size(),&N_comb[0],&z_mid[0],&N_comb_e[0],&z_range[0]);
1121             // z_range_gr_draw -> GetYaxis() -> SetRangeUser(-650,650);
1122             // z_range_gr_draw -> SetMarkerStyle(20);
1123             // z_range_gr_draw -> Draw("ap");
1124             // zvtx_finder -> Draw("lsame");
1125             // draw_text -> DrawLatex(0.2, 0.82, Form("Event Zvtx %.2f mm, error : #pm%.2f", zvtx_finder -> GetParameter(0), zvtx_finder -> GetParError(0)));
1126             // draw_text -> DrawLatex(0.2, 0.78, Form("Width density : %.2f", ( effi_N_comb.size() / fabs(temp_event_zvtx_info[2] - temp_event_zvtx_info[1]) )));
1127             // draw_text -> DrawLatex(0.2, 0.74, Form("Width : %.2f to %.2f mm", temp_event_zvtx_info[2] , temp_event_zvtx_info[1]));
1128 
1129             
1130 
1131             // effi_sig_range_line -> DrawLine(z_range_gr_draw->GetXaxis()->GetXmin(),temp_event_zvtx_info[1],z_range_gr_draw->GetXaxis()->GetXmax(),temp_event_zvtx_info[1]);
1132             // effi_sig_range_line -> DrawLine(z_range_gr_draw->GetXaxis()->GetXmin(),temp_event_zvtx_info[2],z_range_gr_draw->GetXaxis()->GetXmax(),temp_event_zvtx_info[2]);
1133 
1134 
1135             // temp_event_zvtx -> Draw("hist");
1136             // // zvtx_fitting -> Draw("lsame");
1137             // effi_sig_range_line -> DrawLine(temp_event_zvtx_info[1],0,temp_event_zvtx_info[1],temp_event_zvtx -> GetMaximum()*1.05);
1138             // effi_sig_range_line -> DrawLine(temp_event_zvtx_info[2],0,temp_event_zvtx_info[2],temp_event_zvtx -> GetMaximum()*1.05);
1139             // draw_text -> DrawLatex(0.2, 0.85, Form("eID : %i, Total event hit : %i, innter Ncluster : %i, outer Ncluster : %i",event_i,N_hits,temp_sPH_inner_nocolumn_vec.size(),temp_sPH_outer_nocolumn_vec.size()));
1140             // // draw_text -> DrawLatex(0.2, 0.84, Form("Gaus fit mean : %.3f mm",zvtx_fitting -> GetParameter(1)));
1141             // draw_text -> DrawLatex(0.2, 0.82, Form("EffiSig min : %.2f mm, max : %.2f mm",temp_event_zvtx_info[1],temp_event_zvtx_info[2]));
1142             // draw_text -> DrawLatex(0.2, 0.79, Form("EffiSig avg : %.2f mm",temp_event_zvtx_info[0]));
1143 
1144             if(draw_event_display && (event_i % print_rate) == 0){c2 -> Print(Form("%s/folder_%s_advanced/temp_event_display.pdf",mother_folder_directory.c_str(),file_name.c_str()));}
1145             pad_xy -> Clear();
1146             pad_rz -> Clear();
1147             pad_z  -> Clear();
1148 
1149             temp_event_xy -> Delete();
1150             temp_event_rz -> Delete();
1151             // z_range_gr_draw -> Delete();
1152 
1153         }
1154         // cout<<"test tag 3"<<endl;
1155 
1156         for ( int inner_i = 0; inner_i < temp_sPH_inner_nocolumn_vec.size(); inner_i++ )
1157         {
1158             inner_pos_xy -> Fill(temp_sPH_inner_nocolumn_vec[inner_i].x,temp_sPH_inner_nocolumn_vec[inner_i].y);
1159             inner_outer_pos_xy -> Fill(temp_sPH_inner_nocolumn_vec[inner_i].x,temp_sPH_inner_nocolumn_vec[inner_i].y);
1160         }
1161 
1162         for ( int outer_i = 0; outer_i < temp_sPH_outer_nocolumn_vec.size(); outer_i++ )
1163         {
1164             outer_pos_xy -> Fill(temp_sPH_outer_nocolumn_vec[outer_i].x,temp_sPH_outer_nocolumn_vec[outer_i].y);
1165             inner_outer_pos_xy -> Fill(temp_sPH_outer_nocolumn_vec[outer_i].x,temp_sPH_outer_nocolumn_vec[outer_i].y);
1166         }
1167 
1168         // cout<<"test point 7"<<endl;
1169 
1170         temp_event_zvtx_info = {-1000,-1000,-1000};
1171         temp_event_zvtx_vec.clear();
1172         temp_event_zvtx -> Reset("ICESM");
1173         good_track_xy_vec.clear();
1174         good_track_rz_vec.clear();
1175         good_comb_rz_vec.clear();
1176         good_comb_xy_vec.clear();
1177         good_comb_phi_vec.clear();
1178         temp_sPH_nocolumn_rz_vec.clear(); temp_sPH_nocolumn_rz_vec = vector<vector<double>>(2);
1179         temp_sPH_nocolumn_vec.clear(); temp_sPH_nocolumn_vec = vector<vector<double>>(2);
1180         temp_sPH_inner_nocolumn_vec.clear();
1181         temp_sPH_outer_nocolumn_vec.clear();
1182         N_comb.clear();
1183         N_comb_e.clear();
1184         z_mid.clear();
1185         z_range.clear();
1186     } // note : end of event 
1187 
1188     if (draw_event_display) {c2 -> Print(Form("%s/folder_%s_advanced/temp_event_display.pdf)",mother_folder_directory.c_str(),file_name.c_str()));}
1189     c2 -> Clear();
1190     c1 -> Clear();
1191    
1192 
1193     c1 -> cd();
1194     // vector<float> avg_event_zvtx_info = sigmaEff_avg(avg_event_zvtx_vec,Integrate_portion_final);
1195 
1196     // avg_event_zvtx -> SetMinimum( 0 );  avg_event_zvtx -> SetMaximum( avg_event_zvtx->GetBinContent(avg_event_zvtx->GetMaximumBin()) * 1.5 );
1197     // avg_event_zvtx -> Draw("hist");
1198 
1199     // TLatex *ltx = new TLatex();
1200     // ltx->SetNDC();
1201     // ltx->SetTextSize(0.045);
1202     // ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1203     // ltx->DrawLatex(0.54, 0.86, Form("Run %s",run_ID.c_str()));
1204     // ltx->DrawLatex(0.54, 0.81, "Au+Au #sqrt{s_{NN}} = 200 GeV");
1205 
1206     // effi_sig_range_line -> DrawLine(avg_event_zvtx_info[1],0,avg_event_zvtx_info[1],avg_event_zvtx -> GetMaximum());
1207     // effi_sig_range_line -> DrawLine(avg_event_zvtx_info[2],0,avg_event_zvtx_info[2],avg_event_zvtx -> GetMaximum());    
1208     // draw_text -> DrawLatex(0.21, 0.87, Form("EffiSig min : %.2f mm",avg_event_zvtx_info[1]));
1209     // draw_text -> DrawLatex(0.21, 0.83, Form("EffiSig max : %.2f mm",avg_event_zvtx_info[2]));
1210     // draw_text -> DrawLatex(0.21, 0.79, Form("EffiSig avg : %.2f mm",avg_event_zvtx_info[0]));
1211     // c1 -> Print(Form("%s/folder_%s_advanced/avg_event_zvtx.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1212     // c1 -> Clear();
1213 
1214 
1215 
1216     // width_density -> Draw("hist"); 
1217     // c1 -> Print(Form("%s/folder_%s_advanced/width_density.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1218     // c1 -> Clear();
1219 
1220     // zvtx_evt_width -> Draw("hist"); 
1221     // c1 -> Print(Form("%s/folder_%s_advanced/zvtx_evt_width.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1222     // c1 -> Clear();
1223 
1224     // zvtx_evt_fitError_corre -> Draw("colz0"); 
1225     // c1 -> Print(Form("%s/folder_%s_advanced/zvtx_evt_fitError_corre.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1226     // c1 -> Clear();
1227 
1228     // zvtx_evt_nclu_corre -> Draw("colz0"); 
1229     // c1 -> Print(Form("%s/folder_%s_advanced/zvtx_evt_nclu_corre.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1230     // c1 -> Clear();
1231 
1232     // zvtx_evt_width_corre -> Draw("colz0"); 
1233     // c1 -> Print(Form("%s/folder_%s_advanced/zvtx_evt_width_corre.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1234     // c1 -> Clear();
1235 
1236     TLatex *ltx = new TLatex();
1237     ltx->SetNDC();
1238     ltx->SetTextSize(0.045);
1239 
1240     N_cluster_inner_pass -> Draw("hist"); 
1241     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1242     c1 -> Print(Form("%s/folder_%s_advanced/N_cluster_inner_pass.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1243     c1 -> Clear();
1244 
1245     N_cluster_outer_pass -> Draw("hist");
1246     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1247     c1 -> Print(Form("%s/folder_%s_advanced/N_cluster_outer_pass.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1248     c1 -> Clear();
1249 
1250     N_cluster_correlation -> Draw("colz0");
1251     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1252     c1 -> Print(Form("%s/folder_%s_advanced/N_cluster_correlation.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1253     c1 -> Clear();
1254 
1255     DCA_point -> Draw("colz0");
1256     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1257     c1 -> Print(Form("%s/folder_%s_advanced/DCA_point_X%.3fY%.3f_.pdf",mother_folder_directory.c_str(),file_name.c_str(),beam_origin.first,beam_origin.second));
1258     c1 -> Clear();
1259 
1260     DCA_distance_inner_phi -> Draw("colz0");
1261     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1262     c1 -> Print(Form("%s/folder_%s_advanced/DCA_distance_inner_phi_X%.3fY%.3f_.pdf",mother_folder_directory.c_str(),file_name.c_str(),beam_origin.first,beam_origin.second));
1263     c1 -> Clear();
1264 
1265 
1266     TH2F * DCA_distance_inner_phi_peak = (TH2F*)DCA_distance_inner_phi -> Clone();
1267     TF1 * cos_fit = new TF1("cos_fit",cos_func,0,360,4);
1268     cos_fit -> SetParNames("[A]", "[B]", "[C]", "[D]");
1269     cos_fit -> SetParameters(6.5, 0.015,  -185, 0.3);
1270     cos_fit -> SetLineColor(2);
1271     TH2F_threshold(DCA_distance_inner_phi_peak,60);
1272     TProfile * DCA_distance_inner_phi_peak_profile =  DCA_distance_inner_phi_peak->ProfileX();
1273     DCA_distance_inner_phi_peak_profile -> Fit(cos_fit,"N","",50,250);
1274 
1275 
1276     DCA_distance_inner_phi_peak -> Draw("colz0");
1277     DCA_distance_inner_phi_peak_profile -> Draw("same");
1278     cos_fit -> Draw("l same");
1279     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1280     c1 -> Print(Form("%s/folder_%s_advanced/DCA_distance_inner_phi_peak_X%.3fY%.3f_.pdf",mother_folder_directory.c_str(),file_name.c_str(),beam_origin.first,beam_origin.second));
1281     c1 -> Clear();
1282 
1283 
1284     DCA_distance_outer_phi -> Draw("colz0");
1285     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1286     c1 -> Print(Form("%s/folder_%s_advanced/DCA_distance_outer_phi_X%.3fY%.3f_.pdf",mother_folder_directory.c_str(),file_name.c_str(),beam_origin.first,beam_origin.second));
1287     c1 -> Clear();
1288 
1289     z_pos_inner_outer -> Draw("colz0");
1290     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1291     c1 -> Print(Form("%s/folder_%s_advanced/z_pos_inner_outer.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1292     c1 -> Clear();
1293 
1294     z_pos_inner -> Draw("hist");
1295     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1296     c1 -> Print(Form("%s/folder_%s_advanced/z_pos_inner.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1297     c1 -> Clear();
1298 
1299     z_pos_outer -> Draw("hist");
1300     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1301     c1 -> Print(Form("%s/folder_%s_advanced/z_pos_outer.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1302     c1 -> Clear();
1303 
1304     Nhits_good -> Draw("hist");
1305     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1306     c1 -> Print(Form("%s/folder_%s_advanced/Nhits_good.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1307     c1 -> Clear();
1308 
1309     angle_correlation -> Draw("colz0");
1310     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1311     c1 -> Print(Form("%s/folder_%s_advanced/angle_correlation.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1312     c1 -> Clear();
1313 
1314     z_pos_diff -> Draw("hist");
1315     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1316     c1 -> Print(Form("%s/folder_%s_advanced/z_pos_diff.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1317     c1 -> Clear();
1318 
1319     z_pos_diff_angle_diff -> Draw("colz0");
1320     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1321     c1 -> Print(Form("%s/folder_%s_advanced/z_pos_diff_angle_diff.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1322     c1 -> Clear();
1323 
1324     // gaus_fit -> SetParameters(angle_diff -> GetBinContent(angle_diff -> GetMaximumBin()), angle_diff -> GetBinCenter(angle_diff -> GetMaximumBin()), 1, 0);
1325     double_gaus_fit -> SetParameters(angle_diff -> GetBinContent(angle_diff -> GetMaximumBin()), angle_diff -> GetBinCenter(angle_diff -> GetMaximumBin()), 1, 0, angle_diff -> GetBinContent(angle_diff -> GetMaximumBin())/2., angle_diff -> GetBinCenter(angle_diff -> GetMaximumBin()), 3);
1326     // angle_diff -> Fit(gaus_fit,"NQ");
1327     angle_diff -> Fit(double_gaus_fit,"N");
1328     gaus_1->SetParameters(double_gaus_fit -> GetParameter(0),double_gaus_fit -> GetParameter(1), double_gaus_fit -> GetParameter(2), 0);
1329     angle_diff -> Draw("hist");
1330     angle_diff -> SetMinimum(0);
1331     gaus_1 -> Draw("lsame");
1332     // gaus_fit -> Draw("lsame");
1333     double_gaus_fit -> Draw("lsame");
1334     draw_text -> DrawLatex(0.4, 0.87, Form("Sig. gaus mean  : %.3f degree", double_gaus_fit -> GetParameter(1)));
1335     draw_text -> DrawLatex(0.4, 0.83, Form("Sig. gaus width : %.3f degree", double_gaus_fit -> GetParameter(2)));
1336     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1337     c1 -> Print(Form("%s/folder_%s_advanced/angle_diff.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1338     c1 -> Clear();
1339 
1340     // gaus_fit -> SetParameters(DCA_distance_1D -> GetBinContent(DCA_distance_1D -> GetMaximumBin()), DCA_distance_1D -> GetBinCenter(DCA_distance_1D -> GetMaximumBin()), 1, 0);
1341     double_gaus_fit -> SetParameters(DCA_distance_1D -> GetBinContent(DCA_distance_1D -> GetMaximumBin()), DCA_distance_1D -> GetBinCenter(DCA_distance_1D -> GetMaximumBin()), 1, 0, DCA_distance_1D -> GetBinContent(DCA_distance_1D -> GetMaximumBin())/2., DCA_distance_1D -> GetBinCenter(DCA_distance_1D -> GetMaximumBin()), 3);
1342     // DCA_distance_1D -> Fit(gaus_fit,"NQ");
1343     DCA_distance_1D -> Fit(double_gaus_fit,"N");
1344     gaus_1->SetParameters(double_gaus_fit -> GetParameter(0),double_gaus_fit -> GetParameter(1), double_gaus_fit -> GetParameter(2), 0);
1345     DCA_distance_1D -> SetMinimum(0);
1346     DCA_distance_1D -> Draw("hist");
1347     // gaus_fit -> Draw("lsame");
1348     double_gaus_fit -> Draw("lsame");
1349     gaus_1 -> Draw("lsame");
1350     draw_text -> DrawLatex(0.2, 0.87, Form("Sig. gaus mean  : %.3f mm", double_gaus_fit -> GetParameter(1)));
1351     draw_text -> DrawLatex(0.2, 0.83, Form("Sig. gaus width : %.3f mm", double_gaus_fit -> GetParameter(2)));
1352     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1353     c1 -> Print(Form("%s/folder_%s_advanced/DCA_distance_1D_X%.3fY%.3f_.pdf",mother_folder_directory.c_str(),file_name.c_str(),beam_origin.first,beam_origin.second));
1354     c1 -> Clear();
1355 
1356     
1357     angle_diff_DCA_dist -> Draw("colz0");
1358     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1359     c1 -> Print(Form("%s/folder_%s_advanced/angle_diff_DCA_dist.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1360     c1 -> Clear();
1361 
1362     angle_diff_inner_phi -> Draw("colz0");
1363     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1364     c1 -> Print(Form("%s/folder_%s_advanced/angle_diff_inner_phi.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1365     c1 -> Clear();
1366 
1367     inner_pos_xy -> Draw("colz0");
1368     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1369     c1 -> Print(Form("%s/folder_%s_advanced/inner_pos_xy.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1370     c1 -> Clear();
1371 
1372     outer_pos_xy -> Draw("colz0");
1373     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1374     c1 -> Print(Form("%s/folder_%s_advanced/outer_pos_xy.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1375     c1 -> Clear();
1376 
1377     inner_outer_pos_xy -> Draw("colz0");
1378     ltx->DrawLatex(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, "#it{#bf{sPHENIX INTT}} Work-in-progress");
1379     c1 -> Print(Form("%s/folder_%s_advanced/inner_outer_pos_xy.pdf",mother_folder_directory.c_str(),file_name.c_str()));
1380     c1 -> Clear();
1381 
1382     cout<<"the geatest N clu event under the fNhits cut : "<<greatest_N_clu<<endl;
1383 }