CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
ZHelix.cxx
Go to the documentation of this file.
1//
2// ZHelix.cxx
3//
4// $Author: longpx $
5// $Date: 2018/07/23 05:47:20 $
6// $Revision: 1.2 $
7//
8
9#include "BesVisLib/ZHelix.h"
10#include <iostream>
11
12#include <TMath.h>
13
14#ifndef ROOT_TString
15#include <TString.h>
16#endif
17
18#ifndef ZEVIS_ZView
19#include "BesVisLib/BesView.h"
20#endif
21
22#ifndef ZEVIS_ZPad
23#include "TPad.h"
24#endif
25
26using namespace std;
27
28#ifndef __CINT__
30#endif
31
32//__________________________________________________________
33// ZHelix
34// Helix class
35//
36// Drawing options:
37// '3D' - 3 dimensional view
38// 'XY' - XY projection
39// 'ZR' - ZR projection
40//
41ZHelix::ZHelix() : TPolyLine3D() {
42 //
43 // ZHelix standard constructor
44 if ( gDebug ) cout << "ZHelix default ctor called" << endl;
45
46 fRSign = 0;
47 // fSegment = 1.;
48}
49
50//__________________________________________________________
51
52ZHelix::ZHelix(Double_t Azim, Double_t QovR, Double_t QxDh,
53 Double_t refx, Double_t refy,
54 Double_t refz, Double_t TDip,
55 Double_t phii, Double_t phio,
56 Float_t Chi2, Int_t NDoF,
57 EZHelixRangeType RangeType,
58 Double_t RangeMin, Double_t RangeMax) :
59 TPolyLine3D() {
60 //
61 // ZHelix normal constructor
62 if ( gDebug ) cout << "ZHelix normal ctor called" << endl;
63
64 fAzim = Azim;
65 fSinAzim = TMath::Sin(Azim);
66 fCosAzim = TMath::Cos(Azim);
67 fQovR = QovR;
68 fQxDh = QxDh;
69 fRefX = refx;
70 fRefY = refy;
71 fRefZ = refz;
72 fTDip = TDip;
73 fPhiI = phii;
74 fPhiO = phio;
75 fChi2 = Chi2;
76 fNDoF = NDoF;
77 fRType = RangeType;
78 fEnable = kTRUE;
79
80 fRSign = 0;
81 // fSegment = 1.;
82 SetRange(RangeType, RangeMin, RangeMax);
83}
84
85//__________________________________________________________
86
88 //
89 // ZHelix standard destructor
90 if ( gDebug ) {
91 cout << "ZHelix dtor called" << endl;
92 }
93}
94
95//__________________________________________________________
96
98 Double_t RangeMin, Double_t RangeMax) {
99 //
100 // Set range for drawing
101 switch (RangeType) {
102 case kHelixPhi:
103 fRange[0] = RangeMin;
104 fRange[1] = RangeMax;
105 break;
106 case kHelixX:
107 fRange[0] = X2Phi(RangeMin);
108 fRange[1] = X2Phi(RangeMax);
109 break;
110 case kHelixY:
111 fRange[0] = Y2Phi(RangeMin);
112 fRange[1] = Y2Phi(RangeMax);
113 break;
114 case kHelixZ:
115 fRange[0] = Z2Phi(RangeMin);
116 fRange[1] = Z2Phi(RangeMax);
117 break;
118 case kHelixR:
119 fRange[0] = R2Phi(RangeMin);
120 fRange[1] = R2Phi(RangeMax);
121 break;
122 }
123}
124
125//__________________________________________________________
126
127void ZHelix::SetPoints(Option_t *option) {
128 //
129 // Set PolyLine3D points
130 TString opt = option;
131 opt.ToUpper();
132
133 // Get view
134 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
135
136 // check with which sign the segmnents have to added to fRange[0]
137 Int_t sign = 0;
138 if ( fQovR >= 0 )
139 sign = -1;
140 else
141 sign = +1;
142
143 // calculate distance between ranges in rad
144 Double_t degrad = TMath::Pi() / 180.0;
145 Double_t segment = 1. * degrad; // 1 degree segments
146 Double_t df = 0;
147 if ( sign == +1 ) {
148 if ( fRange[1] > fRange[0] )
149 df = fRange[1]-fRange[0];
150 else
151 df = 2*TMath::Pi() + fRange[1]-fRange[0];
152 } else {
153 if ( fRange[1] < fRange[0] )
154 df = fRange[1]-fRange[0];
155 else
156 df = 2*TMath::Pi() - fRange[1]+fRange[0];
157 }
158 // number of segments with degree distance
159 Int_t nSeg = Int_t(TMath::Abs(df) / segment) + 1;
160
161 // solve problem with nseg = 1 , means df too small compared to
162 // segment -> new segment
163 if ( nSeg < 2 ) {
164 segment = 0.01 * degrad;
165 nSeg = Int_t(TMath::Abs(df) / segment) + 1;
166 }
167 // if ( nSeg < 10 ) nSeg = 10;
168
169 // newly calculation of segment
170 segment = TMath::Abs(df) / nSeg;
171
172 Double_t phi, x, y, z, r;
173 TPolyLine3D::SetPolyLine(nSeg+1);
174
175 if ( opt.Contains("3D") ) {
176 // 3D view
177 for ( Int_t i = 0; i <= nSeg; i++ ) {
178 phi = fRange[0] + segment * i * sign;
179 Phi2XYZ(phi, x, y, z);
180 TPolyLine3D::SetPoint(i, x, y, z);
181 }
182 } else if ( opt.Contains("XY") ) {
183 // XY view
184 for ( Int_t i = 0; i <= nSeg; i++ ) {
185 phi = fRange[0] + segment * i * sign;
186 Phi2XYZ(phi, x, y, z);
187 TPolyLine3D::SetPoint(i, x, y, 0);
188 }
189 } else if ( opt.Contains("ZR") ) {
190 // ZR view
191
192 // The track is drawn either in the upper or lower region of
193 // the ZR view depending on how many of its segements lay in
194 // each region. If these numbers are unbalanced, the starting
195 // point of the track is taken as criterium
196 Int_t isgn = 0;
197 for ( Int_t i = 0; i <= nSeg; i++ ) {
198
199 // Get ZR coordinates
200 phi = fRange[0] + segment * i * sign;
201 Phi2ZR(phi, z, r);
202
203 // Set point
204 TPolyLine3D::SetPoint(i, z, r, 0);
205
206 // Get sign for R coordinate
207 isgn += view->GetRSign(phi);
208 if ( i == 0 ) fRSign = view->GetRSign(phi);
209 }
210 if ( isgn != 0 ) fRSign = TMath::Sign(1, isgn);
211
212 // The vertex fitted tracks need to be displaced otherwise they are
213 // are not drawn to emanate from the vertex.
214
215 Float_t z, r, rref, rdisp;
216
217 rref = TMath::Sqrt((fRefX*fRefX)+(fRefY*fRefY));
218
219 if ( (fTrackType != kVctpar) || (fTrackType != kVcparsec) || (fTrackType != kZttrprm) || (fTrackType != kZttrsec) ) {
220
221 // Set R sign for each point
222 for ( Int_t i = 0; i <= nSeg; i++ ) {
223 z = GetP()[i*3];
224 r = GetP()[i*3+1];
225 SetPoint(i, z, r*fRSign, 0);
226 }
227
228 } else {
229
230 for ( Int_t i = 0; i <= nSeg; i++ ) {
231 z = GetP()[i*3];
232 r = GetP()[i*3+1];
233 rdisp = r*fRSign;
234 if (fRSign < 0) rdisp += 2*rref;
235 SetPoint(i, z, rdisp, 0);
236 }
237
238 }
239
240 }
241
242}
243
244//__________________________________________________________
245
246void ZHelix::Phi2XYZ(Double_t phi, Double_t& x, Double_t& y, Double_t& z) {
247 //
248 // Calculate XYZ for a given azimuth
249 x = fRefX - TMath::Sin(phi) / fQovR + fSinAzim * (1/fQovR + fQxDh);
250 y = fRefY + TMath::Cos(phi) / fQovR - fCosAzim * (1/fQovR + fQxDh);
251 z = fRefZ + (fAzim - phi) * fTDip / fQovR;
252}
253
254//__________________________________________________________
255
256void ZHelix::Phi2ZR(Double_t phi, Double_t& z, Double_t& r) {
257 //
258 // Calculate ZR for a given azimuth
259 Double_t x, y;
260 Phi2XYZ(phi, x, y, z);
261 r = TMath::Sqrt(TMath::Power(x,2) + TMath::Power(y,2));
262}
263
264//__________________________________________________________
265
266Double_t ZHelix::X2Phi(Double_t x) {
267 //
268 // Convert x to phi
269 Double_t phi = TMath::ASin(fQovR * (fSinAzim*(1/fQovR + fQxDh) - x + fRefX));
270
271 return phi;
272}
273
274//__________________________________________________________
275
276Double_t ZHelix::Y2Phi(Double_t y) {
277 //
278 // Convert y to phi
279 Double_t phi = TMath::ACos(fQovR * (fCosAzim*(1/fQovR + fQxDh) + y - fRefY));
280
281 return phi;
282}
283
284//__________________________________________________________
285
286Double_t ZHelix::Z2Phi(Double_t z) {
287 //
288 // Convert z to phi
289 Double_t phi = fAzim - fQovR * (z - fRefZ) / fTDip;
290
291 return phi;
292}
293
294//__________________________________________________________
295
296Double_t ZHelix::R2Phi(Double_t r) {
297 //
298 // Convert r to phi
299 Double_t k = 1/fQovR + fQxDh;
300 Double_t my_value = fQovR/(2*k) * (-TMath::Power(r,2) + 1/TMath::Power(fQovR,2) + TMath::Power(k,2));
301 // check if my_value is ouside acos validity range
302 if ( (my_value < -1) || (my_value > 1 ) )
303 return 999999999;
304 Double_t my_phi = TMath::ACos(my_value);
305
306 Double_t phi1 = fAzim - my_phi;
307 Double_t phi2 = fAzim + my_phi;
308
309 Double_t x1 = 0;
310 Double_t y1 = 0;
311 Double_t z1 = 0;
312 Double_t x2 = 0;
313 Double_t y2 = 0;
314 Double_t z2 = 0;
315 Double_t phi = 0;;
316 this->Phi2XYZ(phi1,x1,y1,z1);
317 this->Phi2XYZ(phi2,x2,y2,z2);
318
319
320 // check if phi1 would result in a z value with the correct sign corrsponding
321 // to fTDip
322 if ( TMath::Sign(1.,fTDip) == TMath::Sign(1.,(z1-fRefZ)) ) {
323 // check if phi2 would result in a z value with the correct sign corrsponding
324 // to fTDip
325 if ( TMath::Sign(1.,fTDip) == TMath::Sign(1.,(z2-fRefZ)) ) {
326 // take phi with smallest resulting z difference to fRefZ (Zh)
327 if ( TMath::Abs(z1-fRefZ) <= TMath::Abs(z2-fRefZ) )
328 phi = phi1;
329 else
330 phi = phi2;
331 } else
332 phi = phi1;
333 } else {
334 phi = phi2;
335 }
336
337 return phi;
338}
339
340//__________________________________________________________
341
342void ZHelix::Print(Option_t *option) const {
343 //
344 // Dump the helix attributes
345 TString opt = option;
346 opt.ToUpper();
347
348 cout << endl
349 << "Parameters of helix " << this->GetName() << ":" << endl
350 << "Azimuth = " << fAzim << endl
351 << "Q/R = " << fQovR << endl
352 << "Q*D_h = " << fQxDh << endl
353 << "Z_h = " << fRefZ << endl
354 << "cot(Dip) = " << fTDip << endl
355 << "PhiI = " << fPhiI << endl
356 << "PhiO = " << fPhiO << endl
357 << "Chi2 = " << fChi2 << endl
358 << "D.o.F. = " << fNDoF << endl
359 << "RangeType = " << fRType << endl
360 << "Range: " << fRange[0] << " -> " << fRange[1] << endl;
361 if ( opt.Contains("ALL") ) TPolyLine3D::Print("ALL");
362 cout << endl;
363}
364
365//__________________________________________________________
366
367void ZHelix::Draw(Option_t *option) {
368 //
369 // Draw this helix with its current attributes.
370 AppendPad(option);
371}
372
373//__________________________________________________________
374
375void ZHelix::Paint(Option_t *option) {
376 //
377 // Draw this helix with its current attributes
378 TString opt = option;
379 opt.ToUpper();
380
381 if ( ( (fRange[1] < fRange[0]) || (fRange[1] > fRange[0]) ) && fEnable ) {
382 SetPoints(option);
383 TPolyLine3D::Paint("SAME");
384 }
385}
386
387//__________________________________________________________
388
389Double_t ZHelix::Phi2S(Double_t phi) {
390 //
391 // calculates pathlength for phi
392
393 return -(phi-fAzim)/fQovR;
394
395}
396
397
398
399
float Float_t
Double_t phi2
Double_t x[10]
Double_t phi1
ClassImp(ZHelix) ZHelix
Definition ZHelix.cxx:29
EZHelixRangeType
Definition ZHelix.h:20
@ kHelixY
Definition ZHelix.h:23
@ kHelixX
Definition ZHelix.h:22
@ kHelixPhi
Definition ZHelix.h:21
@ kHelixZ
Definition ZHelix.h:24
@ kHelixR
Definition ZHelix.h:25
@ kVcparsec
Definition ZHelix.h:34
@ kVctpar
Definition ZHelix.h:33
@ kZttrsec
Definition ZHelix.h:38
@ kZttrprm
Definition ZHelix.h:37
virtual Int_t GetRSign(Float_t Phi)
Definition BesView.cxx:717
Double_t fRefZ
Definition ZHelix.h:52
Double_t R2Phi(Double_t r)
Definition ZHelix.cxx:296
void Phi2ZR(Double_t phi, Double_t &z, Double_t &r)
Definition ZHelix.cxx:256
void SetRange(EZHelixRangeType RangeType, Double_t RangeMin, Double_t RangeMax)
Definition ZHelix.cxx:97
Double_t fTDip
Definition ZHelix.h:49
Double_t Y2Phi(Double_t y)
Definition ZHelix.cxx:276
Double_t fSinAzim
Definition ZHelix.h:57
virtual void Print(Option_t *option="") const
Definition ZHelix.cxx:342
Double_t fRange[2]
Definition ZHelix.h:53
Double_t fQxDh
Definition ZHelix.h:48
Double_t fPhiI
sign of radius
Definition ZHelix.h:61
Double_t fRefX
Definition ZHelix.h:50
Double_t fCosAzim
Definition ZHelix.h:58
TrackType fTrackType
Definition ZHelix.h:45
virtual void SetPoints(Option_t *option="3D")
Definition ZHelix.cxx:127
Int_t fRSign
Definition ZHelix.h:60
Float_t fChi2
Definition ZHelix.h:55
Double_t fAzim
Definition ZHelix.h:46
Double_t X2Phi(Double_t x)
Definition ZHelix.cxx:266
virtual void Paint(Option_t *option="3D")
Definition ZHelix.cxx:375
void Phi2XYZ(Double_t phi, Double_t &x, Double_t &y, Double_t &z)
Definition ZHelix.cxx:246
Double_t fRefY
Definition ZHelix.h:51
Double_t fPhiO
Definition ZHelix.h:62
virtual void Draw(Option_t *option="3D")
Definition ZHelix.cxx:367
Bool_t fEnable
Definition ZHelix.h:63
Double_t Phi2S(Double_t phi)
Definition ZHelix.cxx:389
virtual ~ZHelix()
Definition ZHelix.cxx:87
virtual void SetPoint(Int_t point, Double_t x, Double_t y, Double_t z)
Definition ZHelix.h:94
Int_t fNDoF
Definition ZHelix.h:56
Double_t Z2Phi(Double_t z)
Definition ZHelix.cxx:286
Double_t fQovR
Definition ZHelix.h:47
EZHelixRangeType fRType
Definition ZHelix.h:54