Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:13:29

0001 #ifndef HIT_H
0002 #define HIT_H
0003 
0004 #include <cmath>
0005 #include <iostream>
0006 #include <stdio.h>
0007 
0008 #include <TObject.h>
0009 #include <TRandom3.h>
0010 #include <TVector3.h>
0011 
0012 using namespace std;
0013 
0014 class Hit : public TObject
0015 {
0016   public:
0017     Hit();
0018     Hit(float, float, float, float, float, float, int);
0019     Hit(float, float); // simple construct
0020     ~Hit();
0021 
0022     float posX();
0023     float posY();
0024     float posZ();
0025     float rho();
0026     float vtxX();
0027     float vtxY();
0028     float vtxZ();
0029     float Eta();
0030     float Phi();
0031     float R();
0032     int Layer();
0033     pair<float, float> Edge();
0034 
0035     void Update();
0036     void SetPos(float, float, float);
0037     void SetVtx(float, float, float);
0038     void SetEdge(float, float);
0039     void SetMatchedTkl();
0040     bool IsMatchedTkl();
0041     void Print();
0042 
0043     TVector3 VecPos();
0044     TVector3 VecVtx();
0045     TVector3 VecRel();
0046 
0047   private:
0048     float _x;
0049     float _y;
0050     float _z;
0051     float _vtxX;
0052     float _vtxY;
0053     float _vtxZ;
0054     float _eta;
0055     float _phi;
0056     float _R;
0057     int _layer;
0058     pair<float, float> _edge;
0059     bool _matched_tkl;
0060     TVector3 vechit;
0061     TVector3 vecvtx;
0062     TVector3 vecrel;
0063 };
0064 
0065 Hit::Hit()
0066 {
0067     vechit.SetXYZ(0, 0, 0);
0068     vecvtx.SetXYZ(0, 0, 0);
0069     _layer = -999;
0070     vecrel = vechit - vecvtx;
0071     _eta = vecrel.Eta();
0072     _phi = vecrel.Phi();
0073     _R = vecrel.Mag();
0074     _matched_tkl = false;
0075 }
0076 
0077 Hit::Hit(float x, float y, float z, float vtxX, float vtxY, float vtxZ, int layer)
0078 {
0079     vechit.SetXYZ(x, y, z);
0080     vecvtx.SetXYZ(vtxX, vtxY, vtxZ);
0081     _layer = layer;
0082     vecrel = vechit - vecvtx;
0083     _eta = vecrel.Eta();
0084     _phi = vecrel.Phi();
0085     _R = vecrel.Mag();
0086     _matched_tkl = false;
0087 }
0088 
0089 Hit::Hit(float eta, float phi)
0090 {
0091     _eta = eta;
0092     _phi = phi;
0093     _matched_tkl = false;
0094 }
0095 
0096 Hit::~Hit() {}
0097 
0098 float Hit::posX() { return (vechit.X()); }
0099 
0100 float Hit::posY() { return (vechit.Y()); }
0101 
0102 float Hit::posZ() { return (vechit.Z()); }
0103 
0104 float Hit::rho() { return (sqrt(vechit.X() * vechit.X() + vechit.Y() * vechit.Y())); }
0105 
0106 float Hit::vtxX() { return (vecvtx.X()); }
0107 
0108 float Hit::vtxY() { return (vecvtx.Y()); }
0109 
0110 float Hit::vtxZ() { return (vecvtx.Z()); }
0111 
0112 float Hit::Eta() { return (_eta); } // with respect to the vertex that it associates to
0113 
0114 float Hit::Phi() { return (_phi); } // with respect to the vertex that it associates to
0115 
0116 float Hit::R() { return (_R); } // with respect to the vertex that it associates to
0117 
0118 int Hit::Layer() { return (_layer); }
0119 
0120 pair<float, float> Hit::Edge() { return (_edge); }
0121 
0122 void Hit::SetPos(float x, float y, float z) { vechit.SetXYZ(x, y, z); }
0123 
0124 void Hit::SetVtx(float vtxX, float vtxY, float vtxZ) { vecvtx.SetXYZ(vtxX, vtxY, vtxZ); }
0125 
0126 void Hit::SetEdge(float edge1, float edge2) { _edge = make_pair(edge1, edge2); }
0127 
0128 void Hit::Update()
0129 {
0130     vecrel = vechit - vecvtx;
0131     _eta = vecrel.Eta();
0132     _phi = vecrel.Phi();
0133     _R = vecrel.Mag();
0134 }
0135 
0136 void Hit::SetMatchedTkl() { _matched_tkl = true; }
0137 
0138 bool Hit::IsMatchedTkl() { return _matched_tkl; }
0139 
0140 TVector3 Hit::VecPos() { return (vechit); }
0141 
0142 TVector3 Hit::VecVtx() { return (vecvtx); }
0143 
0144 TVector3 Hit::VecRel() { return (vecrel); }
0145 
0146 void Hit::Print() { printf("[Hit::Print()] (posX, posY, posZ) = (%f, %f, %f), (vtxX, vtxY, vtxZ) = (%f, %f, %f), (eta, phi) = (%f, %f) \n", vechit.X(), vechit.Y(), vechit.Z(), vecvtx.X(), vecvtx.Y(), vecvtx.Z(), vecrel.Eta(), vecrel.Phi()); }
0147 
0148 void UpdateHits(vector<Hit *> &Hits, vector<float> PV)
0149 {
0150     for (auto &hit : Hits)
0151     {
0152         hit->SetVtx(PV[0], PV[1], PV[2]);
0153         hit->Update();
0154     }
0155 }
0156 
0157 Hit *RandomHit(float etaMin, float etaMax, float phiMin, float phiMax)
0158 {
0159     float eta = etaMin + (etaMax - etaMin) * gRandom->Rndm();
0160     float phi = phiMin + (phiMax - phiMin) * gRandom->Rndm();
0161     Hit *randhit = new Hit(eta, phi);
0162     randhit->SetPos(-999., -999., -999.);
0163     randhit->SetVtx(0., 0., 0.);
0164     return randhit;
0165 }
0166 
0167 // For mis-alignment
0168 
0169 #endif