ATLAS Offline Software
ShapeCreator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "ShapeCreator.h"
6 
7 #include "TLine.h"
8 #include "TArc.h"
9 #include "TBox.h"
10 #include "TArrow.h"
11 #include "TPolyLine.h"
12 #include "TText.h"
13 //#include "CLHEP/Vector/ThreeVector.h"
14 #include "TVector3.h"
15 
16 #include <iostream>
17 //#include <math.h>
18 #include "TMath.h"
19 
21  m_projection(0){
22 }
23 
24 //void ShapeCreator::applyProjection(const CLHEP::Hep3Vector& pos, double& x1, double& x2) {
25 void ShapeCreator::applyProjection(const TVector3& pos, double& x1, double& x2) {
26  //void ShapeCreator::applyProjection(const Hep3Vector& pos, double& x1, double& x2){
27 
28  if(m_projection == 0) {
29  x1 = pos.x();
30  x2 = pos.y();
31  } else if(m_projection == 1) {
32  x1 = pos.x();
33  x2 = pos.z();
34  } else if(m_projection == 2) {
35  x1 = pos.z();
36  x2 = pos.y();
37  } else if(m_projection == 3) {
38  // Cylindrical Coordinates: Z Phi
39 
40  //const double phiFactor = 180. / TMath::Pi(); // use deg
41  const double phiFactor = 1000.; // use mrad
42  x1 = pos.z();
43  x2 = pos.Phi() * phiFactor;
44 
45  } else if(m_projection == 4) {
46  // Cylindrical Coordinates: Z vs. R*Phi
47  x1 = pos.z();
48  x2 = pos.Phi() * pos.Perp();
49  }
50 
51 }
52 
53 void ShapeCreator::applyDirectionProjectionUnit(const TVector3& dir, double& x1, double& x2, const TVector3& pos) {
54  //void ShapeCreator::applyProjection(const Hep3Vector& pos, double& x1, double& x2){
55 
56  if(m_projection == 0) {
57  x1 = dir.x();
58  x2 = dir.y();
59  } else if(m_projection == 1) {
60  x1 = dir.x();
61  x2 = dir.z();
62  } else if(m_projection == 2) {
63  x1 = dir.z();
64  x2 = dir.y();
65  } else if(m_projection == 3) {
66  // Cylindrical Coordinates: Z Phi
67  //const double phiFactor = 180. / TMath::Pi(); // use deg
68  const double phiFactor = 1000.; // use mrad
69  x1 = dir.z();
70  // directions:
71  TVector3 pos2(pos+dir);
72  x2 = (pos2.Phi() - pos.Phi()) * phiFactor;
73 // if (radius != 0.){
74 // //x2 = atan(sqrt(pow(dir.x(),2.)+pow(dir.y(),2.))/radius) * phiFactor;
75 // x2 = atan(dir.Perp()/radius) * phiFactor;
76 // //std::cout << "radius: " << radius << ", dir.Perp:" << dir.Perp() << std::endl;
77 // } else {
78 // x2=0.;
79 // }
80 
81  } else if(m_projection == 4) {
82  // Cylindrical Coordinates: Z vs. R*Phi
83  x1 = dir.z();
84  x2 = dir.Phi() * dir.Perp();
85  }
86 
87  double length = sqrt(x1*x1 + x2*x2);
88  if (length >0) {
89  x1/=length;
90  x2/=length;
91  }
92 
93 }
94 
96 //void ShapeCreator::setProjection(int p, double parameter) {
97  if(p != 0 && p != 1 && p != 2 && p != 3 && p != 4)
98  std::cout << "ERROR Wrong projection " << std::endl;
99  m_projection = p;
100  //m_parameter = parameter;
101 // std::cout << "ShapeCreator: using projection type " << m_projection << std::endl;
102 }
103 
104 
105 //TLine* ShapeCreator::createLine(const CLHEP::Hep3Vector& pos, const CLHEP::Hep3Vector& dir, double length) {
106 TLine* ShapeCreator::createLine(const TVector3& pos, const TVector3& dir, double length) {
107  double x1,x2;
108  double dx1,dx2;
109 
112 // std::cout << "ShapeCreator: creating line from (" << x1 << "," << x2 << ") to ("<< dx1 << "," << dx2 << ") " << std::endl;
113 
114  double xu1 = x1 + 0.5*dx1*length;
115  double xu2 = x2 + 0.5*dx2*length;
116  double xl1 = x1 - 0.5*dx1*length;
117  double xl2 = x2 - 0.5*dx2*length;
118 
119  return new TLine(xu1,xu2,xl1,xl2);
120 // return new TLine(x1, x2, x1+dx1*length, x2+dx2*length);
121 }
122 
123 TLine* ShapeCreator::createLine(const TVector3& pos1, const TVector3& pos2) {
124  double x1,y1;
125  double x2,y2;
126 
127  applyProjection(pos1,x1,y1);
128  applyProjection(pos2,x2,y2);
129 
130  return new TLine(x1,y1,x2,y2);
131 }
132 
133 TLine* ShapeCreator::createOrthogonalLine(const TVector3& pos, const TVector3& dir, double length){
134  double x1,x2;
135  double dx1,dx2;
136 
139 
140  double xu1 = x1 + 0.5*dx2*length;
141  double xu2 = x2 - 0.5*dx1*length;
142  double xl1 = x1 - 0.5*dx2*length;
143  double xl2 = x2 + 0.5*dx1*length;
144 
145  return new TLine(xu1,xu2,xl1,xl2);
146 // return new TLine(x1, x2, x1-dx2*length, x2+dx1*length);
147 }
148 
149 TArrow* ShapeCreator::createArrow(const TVector3& pos, const TVector3& dir, double length) {
150  double x1,x2;
151  double dx1,dx2;
152 
155 // std::cout << "ShapeCreator: creating line from (" << x1 << "," << x2 << ") to ("<< dx1 << "," << dx2 << ") " << std::endl;
156 
157 // return new TLine(xu1,xu2,xl1,xl2);
158  return new TArrow(x1, x2, x1+dx1*length, x2+dx2*length);
159 }
160 
161 TPolyLine* ShapeCreator::createTriangle(const TVector3& pos, const TVector3& dir, double length){
162  double x1,x2;
163  double dx1,dx2;
164 
167  Double_t x[3] = { x1+(dx2/2.)*length ,x1+dx1*length ,x1-(dx2/2.)*length};
168  Double_t y[3] = { x2-(dx1/2.)*length ,x2+dx2*length, x2+(dx1/2.)*length};
169 // Double_t x[3] = { x1-(dx1-dx2/2.)*length ,x1 ,x1-(dx1+dx2/2.)*length};
170 // Double_t y[3] = { x2-(dx2+dx1/2.)*length ,x2, x2-(dx2-dx1/2.)*length};
171  return new TPolyLine(3,x,y);
172 }
173 
174 //TArc* ShapeCreator::createArc(const CLHEP::Hep3Vector& pos, double r) {
175 TArc* ShapeCreator::createArc(const TVector3& pos, double r) {
176  double x1,x2;
178 // std::cout << "ShapeCreator: creating circle at (" << x1 << "," << x2 << ") with radius "<< r << std::endl;
179 
180  return new TArc(x1,x2,r);
181 }
182 
183 //TBox* ShapeCreator::createBox(const CLHEP::Hep3Vector& upperleft, const CLHEP::Hep3Vector& lowerright) {
184 TBox* ShapeCreator::createBox(const TVector3& upperleft, const TVector3& lowerright) {
185  double x1,x2;
186  double y1,y2;
187 
188  applyProjection(upperleft,x1,x2);
189  applyProjection(lowerright,y1,y2);
190 
191 
192  return new TBox(x1,x2,y1,y2);
193 }
194 
195 TText* ShapeCreator::createText(const TVector3& pos, const char* text) {
196  double x1,x2;
198  return new TText(x1, x2, text);
199 }
200 
201 TEllipse* ShapeCreator::createEllipse(const TVector3& pos, double r1, double r2) {
202  double x1,x2;
204 // std::cout << "ShapeCreator: creating circle at (" << x1 << "," << x2 << ") with radius "<< r << std::endl;
205 
206  return new TEllipse(x1, x2, r1, r2);
207 }
ShapeCreator::createEllipse
TEllipse * createEllipse(const TVector3 &pos, double r1, double r2)
Definition: ShapeCreator.cxx:201
beamspotman.r
def r
Definition: beamspotman.py:676
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
ShapeCreator.h
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
ShapeCreator::applyDirectionProjectionUnit
void applyDirectionProjectionUnit(const TVector3 &dir, double &x1, double &x2, const TVector3 &pos)
Definition: ShapeCreator.cxx:53
x
#define x
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
ShapeCreator::createArc
TArc * createArc(const TVector3 &pos, double r)
Definition: ShapeCreator.cxx:175
ShapeCreator::createBox
TBox * createBox(const TVector3 &upperleft, const TVector3 &lowerright)
Definition: ShapeCreator.cxx:184
ShapeCreator::createTriangle
TPolyLine * createTriangle(const TVector3 &pos, const TVector3 &dir, double length)
Definition: ShapeCreator.cxx:161
ShapeCreator::createLine
TLine * createLine(const TVector3 &pos, const TVector3 &dir, double length)
Definition: ShapeCreator.cxx:106
makeTRTBarrelCans.y2
tuple y2
Definition: makeTRTBarrelCans.py:18
ShapeCreator::m_projection
int m_projection
Definition: ShapeCreator.h:41
beamspotman.dir
string dir
Definition: beamspotman.py:623
ShapeCreator::createArrow
TArrow * createArrow(const TVector3 &pos, const TVector3 &dir, double length)
Definition: ShapeCreator.cxx:149
ShapeCreator::ShapeCreator
ShapeCreator()
Definition: ShapeCreator.cxx:20
ShapeCreator::createOrthogonalLine
TLine * createOrthogonalLine(const TVector3 &pos, const TVector3 &dir, double length)
Definition: ShapeCreator.cxx:133
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ShapeCreator::setProjection
void setProjection(int p)
Definition: ShapeCreator.cxx:95
ShapeCreator::applyProjection
void applyProjection(const TVector3 &pos, double &x1, double &x2)
Definition: ShapeCreator.cxx:25
y
#define y
makeTransCanvas.text
text
Definition: makeTransCanvas.py:11
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
ShapeCreator::createText
TText * createText(const TVector3 &pos, const char *text)
Definition: ShapeCreator.cxx:195