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.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
91 double photon_nom_x=42.52; //nominal photon position
92 double radian=180.0/3.14;
93 double cl1X=cl1->getPosition().at(0);
94 double cl1Y=cl1->getPosition().at(1);
95 double cl1Z=cl1->getPosition().at(2);
96 double cl2X=cl2->getPosition().at(0);
97 double cl2Y=cl2->getPosition().at(1);
98 double cl2Z=cl2->getPosition().at(2);
99 double cl1E=cl1->getEnergy();
100 double cl2E=cl2->getEnergy();
101
102 double cl1_impact_angle=atan2(cl1Y,cl1X-photon_nom_x)*radian;
103 double cl2_impact_angle=atan2(cl2Y,cl2X-photon_nom_x)*radian;
104 if(cl1_impact_angle<0.)
105 cl1_impact_angle+=360.;
106 if(cl2_impact_angle<0.)
107 cl2_impact_angle+=360.;
108 if (cl1Y>0)
109 return cl2_impact_angle-cl1_impact_angle;
110 else
111 return cl1_impact_angle-cl2_impact_angle;
112}
113
114
115
116bool AnaHelpers::MatchToGBLTracks(int ele_id, int pos_id, Track* & ele_trk, Track* & pos_trk, std::vector<Track*>& trks) {
117
118 bool foundele = false;
119 bool foundpos = false;
120
121 for (auto trk : trks) {
122 if (ele_id == trk->getID()) {
123 ele_trk = trk;
124 foundele = true;
125 }
126 if (pos_id == trk->getID()) {
127 pos_trk = trk;
128 foundpos = true;
129 }
130 }
131 return foundele * foundpos;
132}
133
134Track* AnaHelpers::GetTrackFromParticle(std::vector<Track*>& trks,Particle* part){
135 int trkID=(part->getTrack()).getID();
136 for (auto trk :trks){
137 if (trkID == trk->getID())
138 return trk;
139 }
140 return NULL;
141}
142
143Particle* AnaHelpers::GetParticleFromCluster(std::vector<Particle*>& parts,CalCluster* cluster){
144 CalHit* clusSeed=(CalHit*)cluster->getSeed();
145 for (auto part :parts){
146 CalCluster pClus=part->getCluster();
147 if(pClus.getNHits() == 0)
148 continue;
149 CalHit* pClusSeed=(CalHit*)pClus.getSeed();
150 if ( clusSeed== pClusSeed)
151 return part;
152 }
153 return NULL;
154}
155
156//TODO clean bit up
158
159
160 bool foundele = false;
161 bool foundpos = false;
162
163 for (int ipart = 0; ipart < vtx->getParticles().GetEntries(); ++ipart) {
164
165
166 int pdg_id = ((Particle*)vtx->getParticles().At(ipart))->getPDG();
167 if (debug_) std::cout<<"In Loop "<<pdg_id<< " "<< ipart<<std::endl;
168
169 if (pdg_id == 11) {
170 ele = ((Particle*)vtx->getParticles().At(ipart));
171 foundele=true;
172 if (debug_) std::cout<<"found ele "<< (int)foundele<<std::endl;
173 }
174 else if (pdg_id == -11) {
175 pos = (Particle*)vtx->getParticles().At(ipart);
176 foundpos=true;
177 if (debug_) std::cout<<"found pos "<<(int)foundpos<<std::endl;
178
179 }
180 }
181
182 if (!ele || !pos) {
183 std::cout<<"Vertex formed without ele/pos. Skip."<<std::endl;
184 return false;
185 }
186 if (debug_) std::cout<<"returning "<<(int) (foundele && foundpos) <<std::endl;
187 return foundele && foundpos;
188}
189
190//TODO clean bit up
191bool AnaHelpers::GetParticlesFromVtxAndParticleList(std::vector<Particle*>& parts, Vertex* vtx, Particle*& ele, Particle*& pos) {
192
193
194 bool foundele = false;
195 bool foundpos = false;
196 bool matchele=false;
197 bool matchpos=false;
198 Particle* eleTmp=nullptr;
199 Particle* posTmp=nullptr;
200 for (int ipart = 0; ipart < vtx->getParticles().GetEntries(); ++ipart) {
201
202
203 int pdg_id = ((Particle*)vtx->getParticles().At(ipart))->getPDG();
204 if (debug_) std::cout<<"In Loop "<<pdg_id<< " "<< ipart<<std::endl;
205
206 if (pdg_id == 11) {
207 eleTmp = ((Particle*)vtx->getParticles().At(ipart));
208 foundele=true;
209 if (debug_) std::cout<<"found ele "<< (int)foundele<<std::endl;
210 }
211 else if (pdg_id == -11) {
212 posTmp = (Particle*)vtx->getParticles().At(ipart);
213 foundpos=true;
214 if (debug_) std::cout<<"found pos "<<(int)foundpos<<std::endl;
215
216 }
217 }
218
219 if (!eleTmp || !posTmp) {
220 std::cout<<"Vertex formed without ele/pos. Skip."<<std::endl;
221 return false;
222 }
223
224 double eleEne=eleTmp->getMomentum().at(2);//this is a dumb way to match but particles don't have IDs...
225 double posEne=posTmp->getMomentum().at(2);
226
227 for (auto part :parts){
228
229 if (eleEne == part->getMomentum().at(2)) {
230 matchele=true;
231 ele=part;
232 }
233 if (posEne == part->getMomentum().at(2)) {
234 matchpos=true;
235 pos=part;
236 }
237
238 }
239
240 return foundele && foundpos && matchpos &&matchele;
241}
242
243
245 rotSvt.RotateY(SVT_ANGLE);
246
247 rotSvt_sym = new TMatrixDSym(3);
248
249 (*rotSvt_sym)(0,0) = cos(SVT_ANGLE);
250 (*rotSvt_sym)(0,1) = 0.;
251 (*rotSvt_sym)(0,2) = sin(SVT_ANGLE);
252
253 (*rotSvt_sym)(1,0) = 0.;
254 (*rotSvt_sym)(1,1) = 1.;
255 (*rotSvt_sym)(1,2) = 0.;
256
257 (*rotSvt_sym)(1,0) = -sin(SVT_ANGLE);
258 (*rotSvt_sym)(1,1) = 0.;
259 (*rotSvt_sym)(1,2) = cos(SVT_ANGLE);
260
261 debug_ = false;
262
263}
264
265TVector3 AnaHelpers::rotateToSvtFrame(TVector3 v) {
266
267 v.RotateY(SVT_ANGLE);
268 return v;
269}
270
271TVector3 AnaHelpers::rotationToSvtFrame(const TVector3& v) {
272 return rotSvt*v;
273}
Helper class for hipster analysis.
TRotation rotSvt
description
Definition AnaHelpers.h:114
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:115
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:113
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:116
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:231
std::vector< int > getHitLayers()
Definition Track.h:99