Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:40

0001 #include "InttVertexUtil.h"
0002 
0003 #include <TF1.h>
0004 #include <TMath.h>
0005 
0006 #include <algorithm>
0007 #include <numeric>
0008 #include <vector>
0009 
0010 namespace InttVertexUtil
0011 {
0012   double gaus_func(double* x, double* par)
0013   {
0014     // note : par[0] : size
0015     // note : par[1] : mean
0016     // note : par[2] : width
0017     // note : par[3] : offset
0018     return par[0] * TMath::Gaus(x[0], par[1], par[2]) + par[3];
0019   }
0020 
0021   std::vector<float> sigmaEff(std::vector<float> v, float threshold)
0022   {
0023     sort(v.begin(), v.end());
0024 
0025     int total = v.size();
0026     int max = (int) (threshold * total);
0027 
0028     std::vector<float> start;
0029     std::vector<float> stop;
0030     std::vector<float> width;
0031 
0032     unsigned i = 0;
0033     while (i != v.size() - 1)
0034     {
0035       int count = 0;
0036       unsigned j = i;
0037       while (j != v.size() - 1 && count < max)
0038       {
0039         ++count;
0040         ++j;
0041       }
0042 
0043       if (j != v.size() - 1)
0044       {
0045         start.push_back(v[i]);
0046         stop.push_back(v[j]);
0047         width.push_back(v[j] - v[i]);
0048       }
0049       ++i;
0050     }
0051 
0052     float minwidth = *min_element(width.begin(), width.end());
0053 
0054     unsigned pos = min_element(width.begin(), width.end()) - width.begin();
0055 
0056     float xmin = start[pos];
0057     float xmax = stop[pos];
0058 
0059     // cout<<"sigEffi test return width : "<<minwidth<<" edgel - edger : "<<xmin-xmax<<endl;
0060 
0061     return {minwidth, xmin, xmax};
0062   }
0063 
0064   float vector_average(std::vector<float> input_vector)
0065   {
0066     return accumulate(input_vector.begin(), input_vector.end(), 0.0) / double(input_vector.size());
0067   }
0068 
0069   std::vector<float> sigmaEff_avg(const std::vector<float>& v, float threshold)
0070   {
0071     std::vector<float> sigmaEff_vec = sigmaEff(v, threshold);
0072 
0073     std::vector<float> v_range;
0074     v_range.clear();
0075 
0076     // for (unsigned int i = 0; i < v.size(); i++){
0077     for (auto& vi : v)
0078     {
0079       if (vi >= sigmaEff_vec[1] && vi <= sigmaEff_vec[2])
0080       {
0081         v_range.push_back(vi);
0082       }
0083     }
0084 
0085     // note : return the
0086     // note : 0. the avg among the sigeff range
0087     // note : 1. xmin
0088     // note : 2. xmax
0089     return {vector_average(v_range), sigmaEff_vec[1], sigmaEff_vec[2]};
0090   }
0091 
0092 };  // namespace InttVertexUtil