Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef UTILITIES_H
0002 #define UTILITIES_H
0003 
0004 #include <vector>
0005 
0006 #include <TFile.h>
0007 #include <TMath.h>
0008 #include <TTree.h>
0009 
0010 using namespace std;
0011 
0012 #define PI 3.14159265358979323846
0013 
0014 template <class T> void CleanVec(std::vector<T> &v)
0015 {
0016     std::vector<T>().swap(v);
0017     v.shrink_to_fit();
0018 }
0019 
0020 float deltaPhi(float phi1, float phi2)
0021 {
0022     float dPhi = phi1 - phi2;
0023     if (dPhi > PI)
0024         dPhi -= 2. * PI;
0025     if (dPhi < -1. * PI)
0026         dPhi += 2. * PI;
0027     return dPhi;
0028 }
0029 
0030 float deltaR(float eta1, float phi1, float eta2, float phi2)
0031 {
0032     float dEta, dPhi;
0033     dEta = eta1 - eta2;
0034     dPhi = deltaPhi(phi1, phi2);
0035     return sqrt(dEta * dEta + dPhi * dPhi);
0036 }
0037 
0038 template <typename T> std::string number_to_string(T param_)
0039 {
0040     std::string str;
0041     if (param_ < 0)
0042     {
0043         str += "M";
0044         param_ = std::abs(param_);
0045     }
0046     str += std::to_string(param_);
0047     std::size_t found = str.find('.');
0048     if (found == std::string::npos)
0049         return str;
0050     str.replace(found, 1, "p");
0051     while (*(str.end() - 1) == '0' && *(str.end() - 2) != 'p' && !str.empty())
0052         str.erase(str.end() - 1);
0053     if (*(str.end() - 1) == '0' && *(str.end() - 2) == 'p')
0054         str.erase(str.size() - 2, 2);
0055     return str;
0056 }
0057 
0058 // MVTX stave position
0059 std::vector<tuple<float, float, float, float>> MVTXStavePositionXY()
0060 {
0061     std::vector<tuple<float, float, float, float>> v; // x1, y1, x2, y2
0062     TFile *f = new TFile("./MVTX_geo.root", "READ");
0063     f->cd();
0064     TTree *t = (TTree *)f->Get("tree");
0065     float x1, y1, x2, y2;
0066     t->SetBranchAddress("x1", &x1);
0067     t->SetBranchAddress("y1", &y1);
0068     t->SetBranchAddress("x2", &x2);
0069     t->SetBranchAddress("y2", &y2);
0070 
0071     for (int i = 0; i < t->GetEntries(); i++)
0072     {
0073         t->GetEntry(i);
0074 
0075         v.push_back(make_tuple(x1, y1, x2, y2));
0076     }
0077 
0078     return v;
0079 }
0080 
0081 #endif