BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcDetector.cxx
Go to the documentation of this file.
2#include "Identifier/MdcID.h"
4
5#include "GaudiKernel/Bootstrap.h"
6#include "GaudiKernel/IService.h"
7#include "GaudiKernel/ISvcLocator.h"
8
9
10
11static const int _layPerSL = 4;
12MdcDetector * MdcDetector::_myself = 0;
13bool MdcDetector::_doSag = false;
14
15
17 _doSag = doSag;
18 return instance();
19}
20
22{
23 if( 0 == _myself ) {
24 _myself = new MdcDetector();
25 }
26 return _myself;
27}
28
30{
31
32 std::cout << " +---------------------------------------------------+\n"
33 << " | Creating Mdc Geometry information |\n"
34 << " +---------------------------------------------------+\n";
35
36 IService* ser;
37 StatusCode sc = Gaudi::svcLocator()->getService("MdcGeomSvc",ser);
38 if (!sc.isSuccess())
39 std::cout <<" MdcDetector::Could not open Geometry Service"<<std::endl;
40 MdcGeomSvc *mdcsvc = dynamic_cast<MdcGeomSvc*> (ser);
41 if(!mdcsvc) std::cout <<"MdcDetector::Could not open Geometry Service"<<std::endl;
42
43 _nSWire = mdcsvc->getWireSize();
44 _nLayer = mdcsvc->getLayerSize();
45 _nSlay = mdcsvc->getSuperLayerSize();
46
47 _senseWire = new MdcSWire* [_nSWire];
48 _dclayer = new MdcLayer* [_nLayer];
49 _slayList = new MdcSuperLayer* [_nSlay];
50
51 // build the sense wires
52 for( int iwire = 0; iwire < _nSWire; iwire++ ) {
53 const MdcGeoWire *geowir = mdcsvc->Wire(iwire);
54 HepPoint3D eastP = geowir->Backward()/10.0;
55 HepPoint3D westP = geowir->Forward() /10.0;
56 //std::cout<< "wire ("<<geowir->Layer()<<","<<geowir->Cell()<<") east "<<eastP <<",west " <<westP << std::endl;//yzhang debug
57 double sag=0.;
58 if(_doSag) sag = geowir->Sag()/10.;//mm->cm
59
60 //std::cout<<"sag = "<<sag<<" "<< geowir->Sag()<<std::endl;
61 _senseWire[iwire] = new MdcSWire(eastP, westP, sag, geowir->Id(), geowir->Cell());
62
63
64 }
65
66 // build sense wire layers
67 for( int ilay = 0; ilay < _nLayer; ilay++ ) {
68 const MdcGeoLayer *geolay = mdcsvc->Layer(ilay);
69 int nwir = geolay->NCell();
70 int firstwir = geolay->Wirst();
71 _dclayer[ilay] = new MdcLayer(ilay, nwir, &_senseWire[firstwir],*this);
72 _wires_in_layer[ilay] = nwir;
73 }
74
75 // build pointers to make navigation faster
76 buildpointers();
77
78 // do superlayers
79 // --------------
80 buildSuperLayers();
81 // set nominal cell height for each layer!!!! check!!!!
82 double rOther;
83 for(int ilay = 0; ilay < _nLayer; ilay++) {
84 if( ilay == 0) {
85 rOther = Layer(ilay + 1)->rMid();
86 } else {
87 rOther = Layer(ilay - 1)->rMid();
88 }
89 double height = fabs(Layer(ilay)->rMid() - rOther);
90 const_cast<MdcLayer*>(Layer(ilay))->setCellHeight(height);
91 }
92}
93
94
95
97{
98 for( int iwire = 0; iwire < _nSWire; iwire++ ) {
99 delete _senseWire[iwire];
100 }
101 for( int ilay = 0; ilay < _nLayer; ilay++ ) {
102 delete _dclayer[ilay];
103 }
104 for( int islay =0; islay < _nSlay; islay++ ) {
105 _slayList[islay]->print(std::cout);
106 delete _slayList[islay];
107 }
108
109 delete [] _senseWire;
110 delete [] _dclayer;
111 delete [] _slayList;
112}
113
114
115 void
116MdcDetector::buildpointers(void)
117{
118 // first layers
119 // for (int index=0; index<lastLayNum()-firstLayNum()+1; index++) {
120 for (int index=0; index<_nLayer; index++) {
121 // initialize
122 _nextlay[index]=0; _prevlay[index]=0;
123 _nextlayinvw[index]=0; _prevlayinvw[index]=0;
124 // int layi=index+firstLayNum();
125
126 // if ( !existDet(layi) ) {
127 // ErrMsg(fatal) << " layer # " << layi << " does not exist!" <<endmsg;
128 // }
129 // _dclayer[index] = dchLayer(layi);
130
131 //next and previous pointers
132 // if (existDet(layi+1)) { _nextlay[index] = dchLayer(layi+1); }
133 // if (existDet(layi-1)) { _prevlay[index] = _dclayer[index-1]; }
134
135 if ( index + 1 < _nLayer ) { _nextlay[index] = Layer(index+1); }
136 if ( index > 0 ) { _prevlay[index] = Layer(index-1); }
137
138 //next in view pointer
139 // int iview=dchLayer(layi)->view();
140 int iview = Layer(index)->view();
141 int jndex;
142 // for (jndex=index+1; jndex<lastLayNum()-firstLayNum()+1; jndex++) {
143 for (jndex=index+1; jndex<_nLayer; jndex++) {
144 // int layj=jndex+firstLayNum();
145 // if ( !existDet(layj) ) {
146 // ErrMsg(fatal) << " layer # " << layj << " does not exist!" <<endmsg;
147 // }
148 if ( iview != Layer(jndex)->view() ) continue;
149 _nextlayinvw[index] = Layer(jndex+1);
150 break;
151 } //(int jndex=index+1; _dclayer[jndex].Exist(); jndex++)
152
153 //prev in view pointer
154 for (jndex=index-1; jndex>=0 ; jndex--) {
155 // int layj=jndex+firstLayNum();
156 // if ( !existDet(layj) ) {
157 // ErrMsg(fatal) << " layer # " << layj << " does not exist!" <<endmsg;
158 // }
159 if ( iview!=Layer(jndex)->view() ) continue;
160 _prevlayinvw[index] = Layer(jndex);
161 break;
162 } //(int jndex=index+1; _dclayer[jndex].exist(); jndex++)
163
164 } //(int index=0; _dclayer[index].exist(); index++)
165 }
166
167
168 void
169 MdcDetector::buildSuperLayers(void)
170 {
171 // some initializations
172 _nAxSlay = 0;
173 _nSterSlay[0] = _nSterSlay[1] = 0;
174
175 // _nSlay = _nLayer/_layPerSL;
176
177 _firstSlayNum = 1;
178 _lastSlayNum = _nSlay;
179 // _slayList = new MdcSuperLayer*[_nSlay];
180
181 // initialize pointers
182 _firstSlayInView[0] = _firstSlayInView[1] =_firstSlayInView[2] = 0;
183 _lastSlayInView[0] = _lastSlayInView[1] =_lastSlayInView[2] = 0;
184
185 int islay;
186
187 // build the SuperLayers
188 for (islay = 0; islay < _nSlay; islay++) {
189 // MdcSuperLayer* superlay = new MdcSuperLayer("Dch SuperLayer",1001+islay);
190 MdcSuperLayer* superlay = new MdcSuperLayer(islay);
191 // *_dchslayerset += *superlay;
192 _slayList[islay] = superlay;
193 }
194 _firstSlay = _slayList[0];
195 _lastSlay = _slayList[_nSlay-1];
196
197 // set pointers to Layers in SuperLayers
198 // for (int lay=firstLayNum(); lay<=lastLayNum(); lay++) {
199 for (int lay = 0; lay < _nLayer; lay++) {
200 int superlayer = lay / _layPerSL;
201 int index = lay % _layPerSL;
202 _slayList[superlayer]->addLayer(index,getMdcLayer(lay));
203 }
204 // update SuperLayer data members
205 MdcSuperLayer* oldSlayByView[3] = {0,0,0};
206
207 for (islay = 0; islay < _nSlay; islay++) {
208 const MdcSuperLayer* prev = 0;
209 const MdcSuperLayer* next = 0;
210 // const MdcSuperLayer* prevInView = 0;
211 // const MdcSuperLayer* nextInView = 0;
212
213 // SuperLayer view
214 int iview = _slayList[islay]->layer(0)->view();
215 int viewIndex = iview+1;
216 // count SuperLayer types
217 if ( iview == 0 ) _nAxSlay++;
218 else if ( iview == -1 ) _nSterSlay[0]++;
219 else if ( iview == 1 ) _nSterSlay[1]++;
220
221 // build pointer links
222 if ( islay > 0 ) prev = _slayList[islay - 1];
223 if ( islay < _nSlay-1 ) next = _slayList[islay + 1];
224
225 // fill first and last SuperLayer pointers
226 if (firstSlayInView(iview) == 0) _firstSlayInView[viewIndex] =
227 _slayList[islay];
228 _lastSlayInView[viewIndex] = _slayList[islay];
229
230 _slayList[islay]->updateInfo(prev, next);
231 // now the poiters to SuperLayers of the same view
232 if (oldSlayByView[viewIndex] != 0) {
233 oldSlayByView[viewIndex]->setNextInView(_slayList[islay]);
234 _slayList[islay]->setPrevInView(oldSlayByView[viewIndex]);
235 }
236
237 oldSlayByView[viewIndex] = _slayList[islay];
238 }
239 }
240
241
242
243
244 const MdcSWire*
246 {
247 int wire = MdcID::wire(id);
248 int layer= MdcID::layer(id);
249 return Wire(layer, wire);
250 // unsigned wireid= Layer(layer)->Wirst()+wire;
251 // if( wireid < fWires.size()){
252 // return fWires[wireid];
253 // }
254 // else {
255 // return 0;
256 // }
257 }
258
259 const MdcLayer*
261 {
262 unsigned layerid = MdcID::layer(id);
263 return Layer(layerid);
264 // if (layerid < fLayers.size())
265 // return fLayers[layerid];
266 //
267 // return 0;
268 }
269
MdcLayer * getMdcLayer(int laynum) const
Definition: MdcDetector.h:35
const MdcLayer * Layer(unsigned id) const
Definition: MdcDetector.h:33
static MdcDetector * instance()
Definition: MdcDetector.cxx:21
const MdcSWire * Wire(unsigned id) const
Definition: MdcDetector.h:28
const MdcSuperLayer * firstSlayInView(int iview) const
Definition: MdcDetector.h:48
int NCell(void) const
Definition: MdcGeoLayer.h:165
int Wirst(void) const
Definition: MdcGeoLayer.h:157
const double Sag(void) const
Definition: MdcGeoWire.cxx:12
int Cell(void) const
Definition: MdcGeoWire.h:137
HepPoint3D Forward(void) const
Definition: MdcGeoWire.h:129
int Id(void) const
Definition: MdcGeoWire.h:127
HepPoint3D Backward(void) const
Definition: MdcGeoWire.h:128
const MdcGeoWire *const Wire(unsigned id)
Definition: MdcGeomSvc.cxx:768
const int getSuperLayerSize()
Definition: MdcGeomSvc.cxx:679
const MdcGeoLayer *const Layer(unsigned id)
Definition: MdcGeomSvc.cxx:784
const int getWireSize()
Definition: MdcGeomSvc.cxx:669
const int getLayerSize()
Definition: MdcGeomSvc.cxx:674
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition: MdcID.cxx:49
static int wire(const Identifier &id)
Definition: MdcID.cxx:54
double rMid(void) const
Definition: MdcLayer.h:36
int view(void) const
Definition: MdcLayer.h:28
void print(std::ostream &o=std::cout) const
const MdcLayer * layer(int i) const
Definition: MdcSuperLayer.h:45
void setPrevInView(MdcSuperLayer *sl)
Definition: MdcSuperLayer.h:49
void setNextInView(MdcSuperLayer *sl)
Definition: MdcSuperLayer.h:48
Index next(Index i)
Definition: EvtCyclic3.cc:107
Index prev(Index i)
Definition: EvtCyclic3.cc:96