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