BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesMdcGeoParameter.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2// BOOST --- BESIII Object_Oriented Simulation Tool //
3//---------------------------------------------------------------------------//
4// Description: Handle database I/O and user interface
5// for MDC geometry parameters
6// Author: Yuan Ye(yuany@mail.ihep.ac.cn)
7// Created: 4 Dec, 2003
8// Modified:
9// Comment: Used in "BesMdc" now, should be insert in framwork later
10// The units are "mm" and "rad".
11// Datum plane is the East Endplane of MDC.
12//---------------------------------------------------------------------------//
13
14#include <fstream>
15#include <iostream>
16
17#include <CLHEP/Units/PhysicalConstants.h>
18
19#include "GaudiKernel/Bootstrap.h"
20#include "GaudiKernel/IService.h"
21#include "GaudiKernel/ISvcLocator.h"
22#include "GaudiKernel/Service.h"
23#include "MdcGeomSvc/IMdcGeomSvc.h"
24
25#include "G4Svc/IG4Svc.h"
26#include "MdcSim/BesMdcGeoParameter.hh"
27#include "SimUtil/ReadBoostRoot.hh"
28#include "globals.hh"
29#include <cstdlib>
30
31BesMdcGeoParameter* BesMdcGeoParameter::fPointer = 0;
32
34 if ( !fPointer ) fPointer = new BesMdcGeoParameter();
35 return fPointer;
36}
37
38BesMdcWire::BesMdcWire( double length, double phi, double r, double rotateAngle ) {
39 fLength = length;
40 if ( phi < 0 ) { fPhi = phi + 2 * pi; }
41 else if ( phi >= 2 * pi ) { fPhi = phi - 2 * pi; }
42 else { fPhi = phi; }
43 fRadius = r;
44 fRotateAngle = rotateAngle;
45
46 fX = r * cos( phi );
47 fY = r * sin( phi );
48}
49
50double BesMdcWire::Phi( double z ) const {
51 // double phi=fPhi+fRotateAngle*2*(fLength/2-z)/fLength;
52 // yzhang 2011-12-01
53 double OB = R() * sin( RotateAngle() );
54 double OC = OB * z * 2. / fLength;
55 double phi = fPhi + RotateAngle() - atan2( OC, R() * cos( RotateAngle() ) );
56 // zhangy
57
58 if ( phi < 0 ) { phi += 2 * pi; }
59 else if ( phi >= 2 * pi ) { phi -= 2 * pi; }
60 return phi;
61}
62
63double BesMdcWire::X( double ) { return fX; }
64double BesMdcWire::Y( double ) { return fY; }
65
67 ISvcLocator* svcLocator = Gaudi::svcLocator();
68
69 IG4Svc* m_G4Svc;
70 StatusCode sc = svcLocator->service( "G4Svc", m_G4Svc );
71 if ( !sc.isSuccess() )
72 std::cout << "BesMdcGeoParameter::Could not open G4 Service" << std::endl;
73 if ( m_G4Svc->GetMdcDataInput() == 0 )
74 {
75 cout << "------- get BesMdcGeoParameter from file --------" << endl;
77 }
78 if ( m_G4Svc->GetMdcDataInput() == 1 )
79 {
80 cout << "=======get BesMdcGeoParameter from MdcGeomSvc=======" << endl;
82 }
83
84 // Dump();
85 if ( fPointer )
86 {
87 G4cout << "BesMdcGeoParameter constructed twice." << G4endl;
88 exit( -1 );
89 }
90 fPointer = this;
91}
92
94
95 int i;
96 for ( i = 0; i < fLayerNo; i++ )
97 {
98 if ( fLayer[i].BeginWireNo() <= wireNo && wireNo < fLayer[i].SumWireNo() ) { break; }
99 }
100
101 BesMdcWire temp( fLayer[i].Length(), fWirePhi[wireNo], fLayer[i].R(),
102 fLayer[i].RotateAngle() );
103 return temp;
104}
105
107
108 int i = fSignalLayer[signalLayerNo];
109 int wireNoInLayer = 2 * wireNo + 1 - fLayer[i].FirstWire(); // FirstWire():0,field;1,signal
110 double phi = fLayer[i].Phi();
111 double shiftPhi = fLayer[i].ShiftPhi();
112 double wirePhi;
113 wirePhi = wireNoInLayer * shiftPhi + phi;
114
115 BesMdcWire temp( fLayer[i].Length(), fWirePhi[fLayer[i].BeginWireNo() + wireNoInLayer],
116 fLayer[i].R(), fLayer[i].RotateAngle() );
117 return temp;
118}
119
120const BesMdcLayer& BesMdcGeoParameter::Layer( int layerNumber ) const {
121 if ( layerNumber < 0 || layerNumber > 89 )
122 { cout << "Error: Wrong layerNo: " << layerNumber << endl; }
123 return fLayer[layerNumber];
124}
125
126const BesMdcLayer& BesMdcGeoParameter::SignalLayer( int layerNumber ) const {
127 if ( layerNumber < 0 || layerNumber > 42 )
128 { cout << "Error: Wrong SignallayerNo: " << layerNumber << endl; }
129 return fLayer[fSignalLayer[layerNumber]];
130}
131
133 int wireNo, firstWire;
134 double length, phi, r, rotateCell, rotateAngle;
135 double innerR, outR, z;
136 string name, line;
137
138 G4String geoPath = ReadBoostRoot::GetBoostRoot();
139 if ( !geoPath )
140 {
141 G4cout << "BOOST environment not set!" << G4endl;
142 exit( -1 );
143 }
144 geoPath += "/dat/Mdc.txt";
145
146 ifstream inFile( geoPath );
147 if ( !inFile.good() )
148 {
149 cout << "Error, mdc parameters file not exist" << endl;
150 return;
151 }
152
153 getline( inFile, line );
154 inFile >> fLayerNo >> fWireNo >> fSignalLayerNo >> fSignalWireR >> fFieldWireR;
155
156 inFile.seekg( 1, ios::cur );
157 getline( inFile, line );
158 int i, signalLayer;
159 for ( i = 0; i < fSignalLayerNo; i++ )
160 {
161 inFile >> signalLayer;
162 fSignalLayer[i] = signalLayer - 1;
163 }
164
165 inFile.seekg( 1, ios::cur );
166 getline( inFile, line );
167 getline( inFile, line );
168 for ( i = 0; i < fLayerNo; i++ )
169 {
170 inFile >> name >> wireNo >> length >> r >> phi >> firstWire >> rotateCell;
171 getline( inFile, line );
172
173 rotateAngle = 2 * pi * rotateCell / wireNo;
174
175 fLayer[i].SetName( name );
176 fLayer[i].SetRadius( r );
177 fLayer[i].SetLength( length );
178 fLayer[i].SetRotateCell( rotateCell );
179 fLayer[i].SetRotateAngle( rotateAngle );
180 fLayer[i].SetWireNo( wireNo );
181 fLayer[i].SetShiftPhi( twopi / wireNo );
182 fLayer[i].SetFirstWire( firstWire );
183
184 phi *= ( pi / 180 );
185 if ( phi < 0 ) phi += fLayer[i].ShiftPhi();
186 fLayer[i].SetPhi( phi );
187
188 if ( i == 0 )
189 {
190 fLayer[i].SetSumWireNo( wireNo );
191 fLayer[i].SetBeginWireNo( 0 );
192 }
193 else
194 {
195 fLayer[i].SetBeginWireNo( fLayer[i - 1].SumWireNo() );
196 fLayer[i].SetSumWireNo( fLayer[i - 1].SumWireNo() + wireNo );
197 }
198
199 for ( int j = 0; j < wireNo; j++ )
200 { fWirePhi[fLayer[i].BeginWireNo() + j] = j * fLayer[i].ShiftPhi() + phi; }
201 }
202
203 if ( fLayer[fLayerNo - 1].SumWireNo() != fWireNo )
204 { cout << "Total wire number is not consistant!" << endl; }
205
206 getline( inFile, line );
207 inFile >> fSegmentNo;
208 inFile.seekg( 1, ios::cur );
209 getline( inFile, line );
210 getline( inFile, line );
211
212 for ( i = 0; i < fSegmentNo; i++ )
213 {
214 inFile >> length >> innerR >> outR >> z >> name;
215 getline( inFile, line );
216
217 fMdcSegment[i].SetLength( length );
218 fMdcSegment[i].SetInnerR( innerR );
219 fMdcSegment[i].SetOutR( outR );
220 fMdcSegment[i].SetZ( z );
221 fMdcSegment[i].SetName( name );
222 }
223}
224
225// get BesMdcGeoParameter from MdcGeomSvc
227 ISvcLocator* svcLocator = Gaudi::svcLocator();
228 IMdcGeomSvc* mdcGeomSvc;
229 StatusCode sc = svcLocator->service( "MdcGeomSvc", mdcGeomSvc );
230 if ( !sc.isSuccess() )
231 std::cout << "BesMdcGeoParameter::Could not open Geometry Service" << std::endl;
232
233 fLayerNo = mdcGeomSvc->Misc()->LayerNo();
234 fWireNo = mdcGeomSvc->Misc()->WireNo();
235 fSignalLayerNo = mdcGeomSvc->Misc()->SLayerNo();
236 fSignalWireR = mdcGeomSvc->Misc()->SWireR();
237 fFieldWireR = mdcGeomSvc->Misc()->FWireR();
238
239 int i, signalLayer;
240 for ( i = 0; i < fSignalLayerNo; i++ )
241 {
242 signalLayer = mdcGeomSvc->Layer( i )->SLayer();
243 fSignalLayer[i] = signalLayer - 1;
244 }
245
246 string name;
247 int wireNo, firstWire;
248 double length, r, phi, rotateCell, rotateAngle;
249 for ( i = 0; i < fLayerNo; i++ )
250 {
251 name = mdcGeomSvc->GeneralLayer( i )->LayerName();
252 wireNo = mdcGeomSvc->GeneralLayer( i )->NCell() * 2;
253 length = mdcGeomSvc->GeneralLayer( i )->Length();
254 r = mdcGeomSvc->GeneralLayer( i )->Radius();
255 phi = mdcGeomSvc->GeneralLayer( i )->nomPhi();
256 firstWire = mdcGeomSvc->GeneralLayer( i )->First();
257 rotateCell = mdcGeomSvc->GeneralLayer( i )->nomShift();
258
259 rotateAngle = 2 * pi * rotateCell / wireNo;
260
261 fLayer[i].SetName( name );
262 fLayer[i].SetRadius( r );
263 fLayer[i].SetLength( length );
264 fLayer[i].SetRotateCell( rotateCell );
265 fLayer[i].SetRotateAngle( rotateAngle );
266 fLayer[i].SetWireNo( wireNo );
267 fLayer[i].SetShiftPhi( twopi / wireNo );
268 fLayer[i].SetFirstWire( firstWire );
269 fLayer[i].SetPhi( phi );
270
271 if ( i == 0 )
272 {
273 fLayer[i].SetSumWireNo( wireNo );
274 fLayer[i].SetBeginWireNo( 0 );
275 }
276 else
277 {
278 fLayer[i].SetBeginWireNo( fLayer[i - 1].SumWireNo() );
279 fLayer[i].SetSumWireNo( fLayer[i - 1].SumWireNo() + wireNo );
280 }
281
282 for ( int j = 0; j < wireNo; j++ )
283 { fWirePhi[fLayer[i].BeginWireNo() + j] = j * fLayer[i].ShiftPhi() + phi; }
284 }
285
286 if ( fLayer[fLayerNo - 1].SumWireNo() != fWireNo )
287 { cout << "Total wire number is not consistant!" << endl; }
288
289 double innerR, outR, z;
290 fSegmentNo = mdcGeomSvc->getSegmentNo();
291 for ( i = 0; i < fSegmentNo; i++ )
292 {
293 length = mdcGeomSvc->End( i )->Length();
294 innerR = mdcGeomSvc->End( i )->InnerR();
295 outR = mdcGeomSvc->End( i )->OutR();
296 z = mdcGeomSvc->End( i )->Z();
297 name = mdcGeomSvc->End( i )->Name();
298
299 fMdcSegment[i].SetLength( length );
300 fMdcSegment[i].SetInnerR( innerR );
301 fMdcSegment[i].SetOutR( outR );
302 fMdcSegment[i].SetZ( z );
303 fMdcSegment[i].SetName( name );
304 }
305}
306
308 // cout<<"------BesMdcGeoParameter info :--------"<<endl;
309 cout << " fLayerNo: " << fLayerNo << endl;
310 cout << " fWireNo: " << fWireNo << endl;
311 cout << " fSignalLayerNo: " << fSignalLayerNo << endl;
312 cout << " fSignalWireR: " << fSignalWireR << endl;
313 cout << " fFieldWireR: " << fFieldWireR << endl;
314
315 cout << "fSingalLayer:" << endl;
316 for ( int i = 0; i < fSignalLayerNo; i++ ) { cout << fSignalLayer[i] + 1 << ' '; }
317 cout << endl;
318
319 for ( int i = 0; i < fLayerNo; i++ )
320 {
321 cout << "Layer[" << i << "]: "
322 << " name:" << fLayer[i].Name() << " wireNo:" << fLayer[i].WireNo()
323 << " length: " << fLayer[i].Length() << " r: " << fLayer[i].R();
324 if ( i < 75 ) cout << " phi:" << fLayer[i].Phi() * 180 / pi;
325 else cout << " phi:" << ( fLayer[i].Phi() - fLayer[i].ShiftPhi() ) * 180 / pi;
326 cout << " firstWire: " << fLayer[i].FirstWire()
327 << " rotateCell: " << fLayer[i].RotateCell() << endl;
328 }
329
330 cout << "fSegmentNo:" << fSegmentNo << endl;
331 for ( int j = 0; j < fSegmentNo; j++ )
332 {
333 cout << "length:" << fMdcSegment[j].Length() << " innerR:" << fMdcSegment[j].InnerR()
334 << " outR:" << fMdcSegment[j].OutR() << " z:" << fMdcSegment[j].Z()
335 << " name:" << fMdcSegment[j].Name() << endl;
336 }
337}
const int wireNo
double pi
static BesMdcGeoParameter * GetGeo(void)
const BesMdcLayer & SignalLayer(int) const
const BesMdcLayer & Layer(int) const
BesMdcWire SignalWire(int, int)
virtual int GetMdcDataInput()=0
virtual const MdcGeoEnd *const End(unsigned id)=0
virtual const MdcGeoLayer *const Layer(unsigned id)=0
virtual const int getSegmentNo()=0
virtual const MdcGeoMisc *const Misc(void)=0
virtual const MdcGeoGeneral *const GeneralLayer(unsigned id)=0