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