hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
Loading...
Searching...
No Matches
AnaHelpers.cxx
Go to the documentation of this file.
1#include "AnaHelpers.h"
2
3
4
5std::string AnaHelpers::getFileName(std::string filePath, bool withExtension)
6{
7 char sep = '/';
8
9 size_t i = filePath.rfind(sep, filePath.length());
10 std::string baseFile="";
11
12 if (i != std::string::npos) {
13 baseFile = filePath.substr(i+1, filePath.length() - i);
14 }
15
16 if (withExtension)
17 return baseFile;
18 else {
19 i = baseFile.find_last_of('.');
20 return baseFile.substr(0,i);
21 }
22
23 return "";
24}
25
26/*
27 * checks if cluster is in fiducial region
28 * this was copied from my DST code -- mg
29 */
31 if(clu==NULL)
32 return false;
33 bool in_fid=false;
34 double x_edge_low = -262.74;
35 double x_edge_high = 347.7;
36 double y_edge_low = 33.54;
37 double y_edge_high = 75.18;
38
39 double x_gap_low = -106.66;
40 double x_gap_high = 42.17;
41 double y_gap_high = 47.18;
42
43 double x=clu->getPosition().at(0);
44 double y=clu->getPosition().at(1);
45 y=abs(y);
46
47 if( x>x_edge_low && x < x_edge_high && y > y_edge_low && y < y_edge_high)
48 if ( !(x > x_gap_low && x < x_gap_high && y > y_edge_low && y < y_gap_high) )
49 in_fid = true;
50
51 return in_fid;
52}
53
54void AnaHelpers::InnermostLayerCheck(Track* trk, bool& foundL1, bool& foundL2) {
55 bool isKF = trk->isKalmanTrack();
56 int innerCount = 0;
57 bool hasL1 = false;
58 bool hasL2 = false;
59 bool hasL3 = false;
60 for (int ihit=0; ihit<trk->getHitLayers().size();++ihit) {
61 int hit3d = trk->getHitLayers().at(ihit);
62 if(isKF){
63 if (hit3d == 0 ) {
64 innerCount++;
65 }
66 if (hit3d == 1) {
67 innerCount++;
68 }
69 if (hit3d == 2) {
70 innerCount++;
71 hasL2 = true;
72 }
73 if (hit3d == 3) {
74 innerCount++;
75 hasL3 = true;
76 }
77 }
78 else{
79 if (hit3d == 0 ) {
80 innerCount++;
81 }
82 if (hit3d == 1) {
83 innerCount++;
84 hasL1 = true;
85 }
86 }
87 }
88}
89
90std::vector<int> AnaHelpers::GetTrackHitLayers(Track* trk) {
91 std::vector<int> layer_code = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
92 for (int ihit=0; ihit<trk->getHitLayers().size();ihit++) {
93 int layer = trk->getHitLayers().at(ihit);
94 layer_code.at(layer) = 1;
95 }
96 return layer_code;
97}
98
100 double photon_nom_x=42.52; //nominal photon position
101 double radian=180.0/3.14;
102 double cl1X=cl1->getPosition().at(0);
103 double cl1Y=cl1->getPosition().at(1);
104 double cl1Z=cl1->getPosition().at(2);
105 double cl2X=cl2->getPosition().at(0);
106 double cl2Y=cl2->getPosition().at(1);
107 double cl2Z=cl2->getPosition().at(2);
108 double cl1E=cl1->getEnergy();
109 double cl2E=cl2->getEnergy();
110
111 double cl1_impact_angle=atan2(cl1Y,cl1X-photon_nom_x)*radian;
112 double cl2_impact_angle=atan2(cl2Y,cl2X-photon_nom_x)*radian;
113 if(cl1_impact_angle<0.)
114 cl1_impact_angle+=360.;
115 if(cl2_impact_angle<0.)
116 cl2_impact_angle+=360.;
117 if (cl1Y>0)
118 return cl2_impact_angle-cl1_impact_angle;
119 else
120 return cl1_impact_angle-cl2_impact_angle;
121}
122
123
124
125bool AnaHelpers::MatchToGBLTracks(int ele_id, int pos_id, Track* & ele_trk, Track* & pos_trk, std::vector<Track*>& trks) {
126
127 bool foundele = false;
128 bool foundpos = false;
129
130 for (auto trk : trks) {
131 if (ele_id == trk->getID()) {
132 ele_trk = trk;
133 foundele = true;
134 }
135 if (pos_id == trk->getID()) {
136 pos_trk = trk;
137 foundpos = true;
138 }
139 }
140 return foundele * foundpos;
141}
142
143Track* AnaHelpers::GetTrackFromParticle(std::vector<Track*>& trks,Particle* part){
144 int trkID=(part->getTrack()).getID();
145 for (auto trk :trks){
146 if (trkID == trk->getID())
147 return trk;
148 }
149 return NULL;
150}
151
152Particle* AnaHelpers::GetParticleFromCluster(std::vector<Particle*>& parts,CalCluster* cluster){
153 CalHit* clusSeed=(CalHit*)cluster->getSeed();
154 for (auto part :parts){
155 CalCluster pClus=part->getCluster();
156 if(pClus.getNHits() == 0)
157 continue;
158 CalHit* pClusSeed=(CalHit*)pClus.getSeed();
159 if ( clusSeed== pClusSeed)
160 return part;
161 }
162 return NULL;
163}
164
165//TODO clean bit up
167
168
169 bool foundele = false;
170 bool foundpos = false;
171
172 for (int ipart = 0; ipart < vtx->getParticles().GetEntries(); ++ipart) {
173
174
175 int pdg_id = ((Particle*)vtx->getParticles().At(ipart))->getPDG();
176 if (debug_) std::cout<<"In Loop "<<pdg_id<< " "<< ipart<<std::endl;
177
178 if (pdg_id == 11) {
179 ele = ((Particle*)vtx->getParticles().At(ipart));
180 foundele=true;
181 if (debug_) std::cout<<"found ele "<< (int)foundele<<std::endl;
182 }
183 else if (pdg_id == -11) {
184 pos = (Particle*)vtx->getParticles().At(ipart);
185 foundpos=true;
186 if (debug_) std::cout<<"found pos "<<(int)foundpos<<std::endl;
187
188 }
189 }
190
191 if (!ele || !pos) {
192 std::cout<<"Vertex formed without ele/pos. Skip."<<std::endl;
193 return false;
194 }
195 if (debug_) std::cout<<"returning "<<(int) (foundele && foundpos) <<std::endl;
196 return foundele && foundpos;
197}
198
199//TODO clean bit up
200bool AnaHelpers::GetParticlesFromVtxAndParticleList(std::vector<Particle*>& parts, Vertex* vtx, Particle*& ele, Particle*& pos) {
201
202
203 bool foundele = false;
204 bool foundpos = false;
205 bool matchele=false;
206 bool matchpos=false;
207 Particle* eleTmp=nullptr;
208 Particle* posTmp=nullptr;
209 for (int ipart = 0; ipart < vtx->getParticles().GetEntries(); ++ipart) {
210
211
212 int pdg_id = ((Particle*)vtx->getParticles().At(ipart))->getPDG();
213 if (debug_) std::cout<<"In Loop "<<pdg_id<< " "<< ipart<<std::endl;
214
215 if (pdg_id == 11) {
216 eleTmp = ((Particle*)vtx->getParticles().At(ipart));
217 foundele=true;
218 if (debug_) std::cout<<"found ele "<< (int)foundele<<std::endl;
219 }
220 else if (pdg_id == -11) {
221 posTmp = (Particle*)vtx->getParticles().At(ipart);
222 foundpos=true;
223 if (debug_) std::cout<<"found pos "<<(int)foundpos<<std::endl;
224
225 }
226 }
227
228 if (!eleTmp || !posTmp) {
229 std::cout<<"Vertex formed without ele/pos. Skip."<<std::endl;
230 return false;
231 }
232
233 double eleEne=eleTmp->getMomentum().at(2);//this is a dumb way to match but particles don't have IDs...
234 double posEne=posTmp->getMomentum().at(2);
235
236 for (auto part :parts){
237
238 if (eleEne == part->getMomentum().at(2)) {
239 matchele=true;
240 ele=part;
241 }
242 if (posEne == part->getMomentum().at(2)) {
243 matchpos=true;
244 pos=part;
245 }
246
247 }
248
249 return foundele && foundpos && matchpos &&matchele;
250}
251
252
254 rotSvt.RotateY(SVT_ANGLE);
255
256 rotSvt_sym = new TMatrixDSym(3);
257
258 (*rotSvt_sym)(0,0) = cos(SVT_ANGLE);
259 (*rotSvt_sym)(0,1) = 0.;
260 (*rotSvt_sym)(0,2) = sin(SVT_ANGLE);
261
262 (*rotSvt_sym)(1,0) = 0.;
263 (*rotSvt_sym)(1,1) = 1.;
264 (*rotSvt_sym)(1,2) = 0.;
265
266 (*rotSvt_sym)(1,0) = -sin(SVT_ANGLE);
267 (*rotSvt_sym)(1,1) = 0.;
268 (*rotSvt_sym)(1,2) = cos(SVT_ANGLE);
269
270 debug_ = false;
271
272}
273
274TVector3 AnaHelpers::rotateToSvtFrame(TVector3 v) {
275
276 v.RotateY(SVT_ANGLE);
277 return v;
278}
279
280TVector3 AnaHelpers::rotationToSvtFrame(const TVector3& v) {
281 return rotSvt*v;
282}
Helper class for hipster analysis.
TRotation rotSvt
description
Definition AnaHelpers.h:116
void InnermostLayerCheck(Track *trk, bool &foundL1, bool &foundL2)
Checks if a track has a 3d hit on innermost layer and second innermost layer.
TMatrixDSym * rotSvt_sym
description
Definition AnaHelpers.h:117
std::vector< int > GetTrackHitLayers(Track *trk)
TVector3 rotationToSvtFrame(const TVector3 &v)
Rotate a vector from HPS to SVT Frame via TRotation.
Particle * GetParticleFromCluster(std::vector< Particle * > &parts, CalCluster *cluster)
bool MatchToGBLTracks(int ele_id, int pos_id, Track *&ele_trk, Track *&pos_trk, std::vector< Track * > &trks)
brief description
bool IsECalFiducial(CalCluster *clu)
const double SVT_ANGLE
Angle between SVT system and HPS coordinates.
Definition AnaHelpers.h:115
TVector3 rotateToSvtFrame(TVector3 v)
Rotate a vector from HPS to SVT Frame (i.e. for position/momentum rotation).
bool GetParticlesFromVtxAndParticleList(std::vector< Particle * > &parts, Vertex *vtx, Particle *&ele, Particle *&pos)
double GetClusterCoplanarity(CalCluster *cl1, CalCluster *cl2)
static std::string getFileName(std::string filePath, bool withExtension)
Definition AnaHelpers.cxx:5
bool GetParticlesFromVtx(Vertex *vtx, Particle *&ele, Particle *&pos)
Get the Particles From Vtx object.
Track * GetTrackFromParticle(std::vector< Track * > &trks, Particle *part)
bool debug_
description
Definition AnaHelpers.h:118
TObject * getSeed() const
Definition CalCluster.h:93
double getEnergy() const
Definition CalCluster.h:73
std::vector< double > getPosition() const
Definition CalCluster.h:63
int getNHits() const
Definition CalCluster.h:53
Track getTrack() const
Definition Particle.h:48
std::vector< double > getMomentum() const
Definition Particle.cxx:29
Definition Track.h:32
bool isKalmanTrack() const
Definition Track.h:233
std::vector< int > getHitLayers()
Definition Track.h:101
int getID() const
Definition Track.h:264