BOSS 7.0.6
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 geoPath += "/dat/Mdc.txt";
159
160 ifstream inFile(geoPath);
161 if(!inFile.good()){
162 cout<<"Error, mdc parameters file not exist"<<endl;
163 return;
164 }
165
166 getline(inFile, line);
167 inFile>>fLayerNo>>fWireNo>>fSignalLayerNo>>fSignalWireR>>fFieldWireR;
168
169 inFile.seekg(1,ios::cur);
170 getline(inFile, line);
171 int i,signalLayer;
172 for(i=0; i<fSignalLayerNo; i++){
173 inFile>>signalLayer;
174 fSignalLayer[i]=signalLayer-1;
175 }
176
177 inFile.seekg(1,ios::cur);
178 getline(inFile, line);
179 getline(inFile, line);
180 for( i=0; i<fLayerNo; i++){
181 inFile>>name>>wireNo>>length>>r>>phi>>firstWire>>rotateCell;
182 getline(inFile, line);
183
184 rotateAngle=2*pi*rotateCell/wireNo;
185
186 fLayer[i].SetName(name);fLayer[i].SetRadius(r);
187 fLayer[i].SetLength(length); fLayer[i].SetRotateCell(rotateCell);
188 fLayer[i].SetRotateAngle(rotateAngle); fLayer[i].SetWireNo(wireNo);
189 fLayer[i].SetShiftPhi(twopi/wireNo); fLayer[i].SetFirstWire(firstWire);
190
191 phi*=(pi/180);
192 if(phi<0)phi += fLayer[i].ShiftPhi();
193 fLayer[i].SetPhi(phi);
194
195 if(i==0){
196 fLayer[i].SetSumWireNo(wireNo); fLayer[i].SetBeginWireNo(0);
197 }else{
198 fLayer[i].SetBeginWireNo(fLayer[i-1].SumWireNo());
199 fLayer[i].SetSumWireNo(fLayer[i-1].SumWireNo()+wireNo);
200 }
201
202 for(int j=0; j<wireNo; j++){
203 fWirePhi[fLayer[i].BeginWireNo()+j]=j*fLayer[i].ShiftPhi()+phi;
204 }
205 }
206
207 if(fLayer[fLayerNo-1].SumWireNo()!= fWireNo){
208 cout<<"Total wire number is not consistant!"<<endl;
209 }
210
211 getline(inFile, line);
212 inFile>>fSegmentNo;
213 inFile.seekg(1,ios::cur);
214 getline(inFile, line);
215 getline(inFile, line);
216
217 for(i=0; i<fSegmentNo; i++){
218 inFile>>length>>innerR>>outR>>z>>name;
219 getline(inFile,line);
220
221 fMdcSegment[i].SetLength(length); fMdcSegment[i].SetInnerR(innerR);
222 fMdcSegment[i].SetOutR(outR); fMdcSegment[i].SetZ(z);
223 fMdcSegment[i].SetName(name);
224 }
225
226}
227
228 // get BesMdcGeoParameter from MdcGeomSvc
230 ISvcLocator* svcLocator = Gaudi::svcLocator();
231 IMdcGeomSvc* ISvc;
232 MdcGeomSvc* mdcGeomSvc;
233 StatusCode sc=svcLocator->service("MdcGeomSvc", ISvc);
234 mdcGeomSvc=dynamic_cast<MdcGeomSvc *>(ISvc);
235 if (!sc.isSuccess())
236 std::cout<<"BesMdcGeoParameter::Could not open Geometry Service"<<std::endl;
237
238 fLayerNo= mdcGeomSvc->Misc()->LayerNo();
239 fWireNo=mdcGeomSvc->Misc()->WireNo();
240 fSignalLayerNo=mdcGeomSvc->Misc()->SLayerNo();
241 fSignalWireR=mdcGeomSvc->Misc()->SWireR();
242 fFieldWireR=mdcGeomSvc->Misc()->FWireR();
243
244 int i,signalLayer;
245 for(i=0; i<fSignalLayerNo; i++){
246 signalLayer=mdcGeomSvc->Layer(i)->SLayer();
247 fSignalLayer[i]=signalLayer-1;
248 }
249
250 string name;
251 int wireNo,firstWire;
252 double length, r, phi,rotateCell,rotateAngle;
253 for(i=0;i<fLayerNo;i++){
254 name=mdcGeomSvc->GeneralLayer(i)->LayerName();
255 wireNo=mdcGeomSvc->GeneralLayer(i)->NCell()*2;
256 length= mdcGeomSvc->GeneralLayer(i)->Length();
257 r= mdcGeomSvc->GeneralLayer(i)->Radius();
258 phi=mdcGeomSvc->GeneralLayer(i)->nomPhi();
259 firstWire=mdcGeomSvc->GeneralLayer(i)->First();
260 rotateCell= mdcGeomSvc->GeneralLayer(i)->nomShift();
261
262 rotateAngle=2*pi*rotateCell/wireNo;
263
264 fLayer[i].SetName(name);fLayer[i].SetRadius(r);
265 fLayer[i].SetLength(length); fLayer[i].SetRotateCell(rotateCell);
266 fLayer[i].SetRotateAngle(rotateAngle); fLayer[i].SetWireNo(wireNo);
267 fLayer[i].SetShiftPhi(twopi/wireNo); fLayer[i].SetFirstWire(firstWire);
268 fLayer[i].SetPhi(phi);
269
270 if(i==0){
271 fLayer[i].SetSumWireNo(wireNo); fLayer[i].SetBeginWireNo(0);
272 }else{
273 fLayer[i].SetBeginWireNo(fLayer[i-1].SumWireNo());
274 fLayer[i].SetSumWireNo(fLayer[i-1].SumWireNo()+wireNo);
275 }
276
277 for(int j=0; j<wireNo; j++){
278 fWirePhi[fLayer[i].BeginWireNo()+j]=j*fLayer[i].ShiftPhi()+phi;
279 }
280 }
281
282 if(fLayer[fLayerNo-1].SumWireNo()!= fWireNo){
283 cout<<"Total wire number is not consistant!"<<endl;
284 }
285
286
287 double innerR,outR,z;
288 fSegmentNo=mdcGeomSvc->getSegmentNo();
289 for(i=0;i<fSegmentNo;i++){
290 length=mdcGeomSvc->End(i)->Length();
291 innerR=mdcGeomSvc->End(i)->InnerR();
292 outR=mdcGeomSvc->End(i)->OutR();
293 z=mdcGeomSvc->End(i)->Z();
294 name=mdcGeomSvc->End(i)->Name();
295
296 fMdcSegment[i].SetLength(length); fMdcSegment[i].SetInnerR(innerR);
297 fMdcSegment[i].SetOutR(outR); fMdcSegment[i].SetZ(z);
298 fMdcSegment[i].SetName(name);
299 }
300
301}
302
304 //cout<<"------BesMdcGeoParameter info :--------"<<endl;
305 cout<<" fLayerNo: "<<fLayerNo<<endl;
306 cout<<" fWireNo: "<<fWireNo<<endl;
307 cout<<" fSignalLayerNo: "<<fSignalLayerNo<<endl;
308 cout<<" fSignalWireR: "<<fSignalWireR<<endl;
309 cout<<" fFieldWireR: "<<fFieldWireR<<endl;
310
311 cout<<"fSingalLayer:"<<endl;
312 for(int i=0; i<fSignalLayerNo; i++){
313 cout<<fSignalLayer[i]+1<<' '; }
314 cout<<endl;
315
316 for(int i=0;i<fLayerNo;i++){
317 cout<<"Layer["<<i<<"]: "
318 <<" name:"<<fLayer[i].Name() <<" wireNo:"<<fLayer[i].WireNo()
319 <<" length: "<<fLayer[i].Length() <<" r: "<<fLayer[i].R();
320 if (i<75) cout<<" phi:"<<fLayer[i].Phi()*180/pi;
321 else cout<<" phi:"<<(fLayer[i].Phi()-fLayer[i].ShiftPhi())*180/pi;
322 cout<<" firstWire: "<<fLayer[i].FirstWire()
323 <<" rotateCell: "<<fLayer[i].RotateCell()<<endl;
324 }
325
326 cout<<"fSegmentNo:"<<fSegmentNo<<endl;
327 for(int j=0;j<fSegmentNo;j++){
328 cout<<"length:"<<fMdcSegment[j].Length()
329 <<" innerR:"<<fMdcSegment[j].InnerR()
330 <<" outR:"<<fMdcSegment[j].OutR()
331 <<" z:"<<fMdcSegment[j].Z()
332 <<" name:"<<fMdcSegment[j].Name()<<endl;
333 }
334
335}
336
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
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:800
const MdcGeoEnd *const End(unsigned id)
Definition: MdcGeomSvc.cxx:813
const MdcGeoLayer *const Layer(unsigned id)
Definition: MdcGeomSvc.cxx:784
const int getSegmentNo()
Definition: MdcGeomSvc.cxx:689
const MdcGeoMisc *const Misc(void)
Definition: MdcGeomSvc.cxx:808
static G4String GetBoostRoot()
const float pi
Definition: vector3.h:133