BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcRecROOTGeo.cxx
Go to the documentation of this file.
1//
2// EmcRecROOTGeo
3//
4// May 15, 2007, Created by Miao He
5//
6// Construct ROOT geometry from gdml
7//
8
9#include "EmcRecGeoSvc/EmcRecROOTGeo.h"
10#include "CLHEP/Vector/Rotation.h"
11#include "EmcRecGeoSvc/EmcRecCrystal.h"
12#include "ROOTGeo/EmcROOTGeo.h"
13
14#include "TGeoArb8.h"
15#include <TGeoManager.h>
16
17using namespace std;
18using namespace CLHEP;
19
20EmcRecROOTGeo::EmcRecROOTGeo() { m_crystalMap.clear(); }
21
22EmcRecROOTGeo::~EmcRecROOTGeo() { m_crystalMap.clear(); }
23
25 if ( !gGeoManager ) gGeoManager = new TGeoManager( "BesGeo", "Bes geometry" );
26
27 EmcROOTGeo* fEmcROOTGeo = new EmcROOTGeo();
28 fEmcROOTGeo->SetPhysicalNode();
29
30 // get physical node
31 for ( int part = 0; part < fEmcROOTGeo->GetPartNb(); part++ )
32 {
33 for ( int phi = 0; phi < fEmcROOTGeo->GetPhiNb( part ); phi++ )
34 {
35 for ( int theta = 0; theta < fEmcROOTGeo->GetThetaNb( part ); theta++ )
36 {
37 TGeoPhysicalNode* crystalPhysicalNode =
38 fEmcROOTGeo->GetPhysicalCrystal( part, phi, theta );
39
40 TGeoArb8* arb = (TGeoArb8*)crystalPhysicalNode->GetShape();
41 // TGeoTrap *arb = (TGeoTrap*)crystalPhysicalNode->GetShape();
42
43 double* pRot;
44 pRot = crystalPhysicalNode->GetMatrix()->GetRotationMatrix();
45 Hep3Vector rotX( pRot[0], pRot[3], pRot[6] );
46 Hep3Vector rotY( pRot[1], pRot[4], pRot[7] );
47 Hep3Vector rotZ( pRot[2], pRot[5], pRot[8] );
48 HepRotation rotateCrystalToGlobal( rotX, rotY, rotZ );
49 // cout<<"\nrotation: "<<rotateCrystalToGlobal<<"\n"<<endl;
50
51 Hep3Vector rotTX( pRot[0], pRot[1], pRot[2] );
52 Hep3Vector rotTY( pRot[3], pRot[4], pRot[5] );
53 Hep3Vector rotTZ( pRot[6], pRot[7], pRot[8] );
54 HepRotation rotateGlobalToCrystal( rotTX, rotTY, rotTZ );
55
56 double* pTrans;
57 pTrans = crystalPhysicalNode->GetMatrix()->GetTranslation();
58 Hep3Vector translateCrystalToGlobal( pTrans[0], pTrans[1], pTrans[2] );
59
60 Hep3Vector fPnt[10];
61 for ( int i = 0; i < 8; i++ )
62 {
63 if ( i < 4 )
64 {
65 fPnt[i] = Hep3Vector( arb->GetVertices()[i * 2], arb->GetVertices()[i * 2 + 1],
66 -arb->GetDz() );
67 }
68 else
69 {
70 fPnt[i] = Hep3Vector( arb->GetVertices()[i * 2], arb->GetVertices()[i * 2 + 1],
71 arb->GetDz() );
72 }
73
74 fPnt[i] *= rotateCrystalToGlobal;
75 fPnt[i] += translateCrystalToGlobal;
76 }
77
78 EmcRecCrystal aCrystal;
79 aCrystal.Type( EmcRecCrystal::SixPlane() );
80
81 Hep3Vector tempVec;
82 if ( part == 1 )
83 {
84 tempVec = fPnt[3];
85 fPnt[3] = fPnt[0];
86 fPnt[0] = fPnt[1];
87 fPnt[1] = fPnt[2];
88 fPnt[2] = tempVec;
89 tempVec = fPnt[7];
90 fPnt[7] = fPnt[4];
91 fPnt[4] = fPnt[5];
92 fPnt[5] = fPnt[6];
93 fPnt[6] = tempVec;
94
95 for ( int i = 0; i < 8; i++ ) { aCrystal.Set( i, fPnt[i] ); }
96 FillCrystalMap( aCrystal, part, theta, phi );
97 }
98 else
99 {
100 for ( int i = 0; i < 8; i++ )
101 {
102 if ( i % 2 == 0 )
103 {
104 tempVec = fPnt[i];
105 fPnt[i] = fPnt[i + 1];
106 fPnt[i + 1] = tempVec;
107 }
108 aCrystal.Set( i, fPnt[i] );
109 }
110
111 int sector, nb;
112 if ( theta < 30 )
113 {
114 sector = phi;
115 nb = theta;
116 }
117 else
118 {
119 sector = phi;
120 aCrystal.Type( EmcRecCrystal::SevenPlane() );
121 if ( theta >= 30 && theta < 32 ) { nb = theta - 25; }
122 else { nb = theta - 18; }
123 int newTheta, newPhi;
124 ComputeThetaPhi( part, nb, sector, newTheta, newPhi );
125 Identifier id = EmcID::crystal_id( part, newTheta, newPhi );
126 EmcRecCrystal tempCrystal = m_crystalMap[id];
127
128 aCrystal.Set( 0, tempCrystal.Get( 0 ) );
129 aCrystal.Set( 1, fPnt[0] );
130 aCrystal.Set( 2, fPnt[1] );
131 aCrystal.Set( 3, tempCrystal.Get( 2 ) );
132 aCrystal.Set( 4, tempCrystal.Get( 3 ) );
133 aCrystal.Set( 5, tempCrystal.Get( 4 ) );
134 aCrystal.Set( 6, fPnt[4] );
135 aCrystal.Set( 7, fPnt[5] );
136 aCrystal.Set( 8, tempCrystal.Get( 6 ) );
137 aCrystal.Set( 9, tempCrystal.Get( 7 ) );
138 }
139
140 FillCrystalMap( aCrystal, part, nb, sector );
141 }
142 } // theta
143 } // phi
144 } // part
145
146 delete fEmcROOTGeo;
147}
148
149void EmcRecROOTGeo::FillCrystalMap( EmcRecCrystal& aCrystal, const int part, const int theta,
150 const int phi ) {
151 Identifier id;
152 if ( part == 1 )
153 { // barrel
154 id = EmcID::crystal_id( EmcID::getBARREL(), theta, phi );
155 m_crystalMap[id] = aCrystal;
156 }
157 else
158 { // endcap
159 int newTheta, newPhi;
160 ComputeThetaPhi( part, theta, phi, newTheta, newPhi );
161 id = EmcID::crystal_id( part, newTheta, newPhi );
162 m_crystalMap[id] = aCrystal;
163 }
164}
165
167 return m_crystalMap.find( id )->second;
168}
169
171 return GetCrystal( id ).Center();
172}
173
175 return GetCrystal( id ).FrontCenter();
176}
177
178void EmcRecROOTGeo::ComputeThetaPhi( const int part, const int theta, const int phi,
179 int& newTheta, int& newPhi ) {
180 int sector = phi;
181 if ( ( sector >= 0 ) && ( sector < 3 ) ) sector += 16;
182 // if((sector!=7)&&(sector!=15))
183 {
184 if ( ( theta >= 0 ) && ( theta < 4 ) )
185 {
186 newTheta = 0;
187 newPhi = ( sector - 3 ) * 4 + theta;
188 }
189 else if ( ( theta >= 4 ) && ( theta < 8 ) )
190 {
191 newTheta = 1;
192 newPhi = ( sector - 3 ) * 4 + theta - 4;
193 }
194 else if ( ( theta >= 8 ) && ( theta < 13 ) )
195 {
196 newTheta = 2;
197 newPhi = ( sector - 3 ) * 5 + theta - 8;
198 }
199 else if ( ( theta >= 13 ) && ( theta < 18 ) )
200 {
201 newTheta = 3;
202 newPhi = ( sector - 3 ) * 5 + theta - 13;
203 }
204 else if ( ( theta >= 18 ) && ( theta < 24 ) )
205 {
206 newTheta = 4;
207 newPhi = ( sector - 3 ) * 6 + theta - 18;
208 }
209 else if ( ( theta >= 24 ) && ( theta < 30 ) )
210 {
211 newTheta = 5;
212 newPhi = ( sector - 3 ) * 6 + theta - 24;
213 }
214 }
215
216 if ( part == 2 )
217 {
218 switch ( newTheta )
219 {
220 case 0:
221 if ( newPhi < 32 ) newPhi = 31 - newPhi;
222 else newPhi = 95 - newPhi;
223 break;
224 case 1:
225 if ( newPhi < 32 ) newPhi = 31 - newPhi;
226 else newPhi = 95 - newPhi;
227 break;
228 case 2:
229 if ( newPhi < 40 ) newPhi = 39 - newPhi;
230 else newPhi = 119 - newPhi;
231 break;
232 case 3:
233 if ( newPhi < 40 ) newPhi = 39 - newPhi;
234 else newPhi = 119 - newPhi;
235 break;
236 case 4:
237 if ( newPhi < 48 ) newPhi = 47 - newPhi;
238 else newPhi = 143 - newPhi;
239 break;
240 case 5:
241 if ( newPhi < 48 ) newPhi = 47 - newPhi;
242 else newPhi = 143 - newPhi;
243 default:;
244 }
245 }
246}
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
Definition EmcID.cxx:63
static unsigned int getBARREL()
Definition EmcID.cxx:97
int GetPhiNb(int part)
Get number of phi on part;.
void SetPhysicalNode()
Set the pointers to the physical nodes;.
int GetThetaNb(int part)
Get number of theta on part;.
TGeoPhysicalNode * GetPhysicalCrystal(int part, int phi, int theta)
Get crystal physical node;.
void Set(int index, const HepPoint3D &aPoint)
void ComputeThetaPhi(const int part, const int theta, const int phi, int &newTheta, int &newPhi)
void FillCrystalMap(EmcRecCrystal &, const int, const int, const int)
EmcRecCrystal GetCrystal(const Identifier &id) const
HepPoint3D GetCFrontCenter(const Identifier &id) const
HepPoint3D GetCCenter(const Identifier &id) const