00001 #include "MdcGeom/MdcDetector.h"
00002 #include "Identifier/MdcID.h"
00003 #include "MdcGeomSvc/MdcGeomSvc.h"
00004
00005 #include "GaudiKernel/Bootstrap.h"
00006 #include "GaudiKernel/IService.h"
00007 #include "GaudiKernel/ISvcLocator.h"
00008
00009
00010
00011 static const int _layPerSL = 4;
00012 MdcDetector * MdcDetector::_myself = 0;
00013 bool MdcDetector::_doSag = false;
00014
00015
00016 MdcDetector * MdcDetector::instance(bool doSag){
00017 _doSag = doSag;
00018 return instance();
00019 }
00020
00021 MdcDetector * MdcDetector::instance()
00022 {
00023 if( 0 == _myself ) {
00024 _myself = new MdcDetector();
00025 }
00026 return _myself;
00027 }
00028
00029 MdcDetector::MdcDetector()
00030 {
00031
00032 std::cout << " +---------------------------------------------------+\n"
00033 << " | Creating Mdc Geometry information |\n"
00034 << " +---------------------------------------------------+\n";
00035
00036 IService* ser;
00037 StatusCode sc = Gaudi::svcLocator()->getService("MdcGeomSvc",ser);
00038 if (!sc.isSuccess())
00039 std::cout <<" MdcDetector::Could not open Geometry Service"<<std::endl;
00040 MdcGeomSvc *mdcsvc = dynamic_cast<MdcGeomSvc*> (ser);
00041 if(!mdcsvc) std::cout <<"MdcDetector::Could not open Geometry Service"<<std::endl;
00042
00043 _nSWire = mdcsvc->getWireSize();
00044 _nLayer = mdcsvc->getLayerSize();
00045 _nSlay = mdcsvc->getSuperLayerSize();
00046
00047 _senseWire = new MdcSWire* [_nSWire];
00048 _dclayer = new MdcLayer* [_nLayer];
00049 _slayList = new MdcSuperLayer* [_nSlay];
00050
00051
00052 for( int iwire = 0; iwire < _nSWire; iwire++ ) {
00053 const MdcGeoWire *geowir = mdcsvc->Wire(iwire);
00054 HepPoint3D eastP = geowir->Backward()/10.0;
00055 HepPoint3D westP = geowir->Forward() /10.0;
00056
00057 double sag=0.;
00058 if(_doSag) sag = geowir->Sag()/10.;
00059
00060
00061 _senseWire[iwire] = new MdcSWire(eastP, westP, sag, geowir->Id(), geowir->Cell());
00062
00063
00064 }
00065
00066
00067 for( int ilay = 0; ilay < _nLayer; ilay++ ) {
00068 const MdcGeoLayer *geolay = mdcsvc->Layer(ilay);
00069 int nwir = geolay->NCell();
00070 int firstwir = geolay->Wirst();
00071 _dclayer[ilay] = new MdcLayer(ilay, nwir, &_senseWire[firstwir],*this);
00072 _wires_in_layer[ilay] = nwir;
00073 }
00074
00075
00076 buildpointers();
00077
00078
00079
00080 buildSuperLayers();
00081
00082 double rOther;
00083 for(int ilay = 0; ilay < _nLayer; ilay++) {
00084 if( ilay == 0) {
00085 rOther = Layer(ilay + 1)->rMid();
00086 } else {
00087 rOther = Layer(ilay - 1)->rMid();
00088 }
00089 double height = fabs(Layer(ilay)->rMid() - rOther);
00090 const_cast<MdcLayer*>(Layer(ilay))->setCellHeight(height);
00091 }
00092 }
00093
00094
00095
00096 MdcDetector::~MdcDetector()
00097 {
00098 for( int iwire = 0; iwire < _nSWire; iwire++ ) {
00099 delete _senseWire[iwire];
00100 }
00101 for( int ilay = 0; ilay < _nLayer; ilay++ ) {
00102 delete _dclayer[ilay];
00103 }
00104 for( int islay =0; islay < _nSlay; islay++ ) {
00105 _slayList[islay]->print(std::cout);
00106 delete _slayList[islay];
00107 }
00108
00109 delete [] _senseWire;
00110 delete [] _dclayer;
00111 delete [] _slayList;
00112 }
00113
00114
00115 void
00116 MdcDetector::buildpointers(void)
00117 {
00118
00119
00120 for (int index=0; index<_nLayer; index++) {
00121
00122 _nextlay[index]=0; _prevlay[index]=0;
00123 _nextlayinvw[index]=0; _prevlayinvw[index]=0;
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 if ( index + 1 < _nLayer ) { _nextlay[index] = Layer(index+1); }
00136 if ( index > 0 ) { _prevlay[index] = Layer(index-1); }
00137
00138
00139
00140 int iview = Layer(index)->view();
00141 int jndex;
00142
00143 for (jndex=index+1; jndex<_nLayer; jndex++) {
00144
00145
00146
00147
00148 if ( iview != Layer(jndex)->view() ) continue;
00149 _nextlayinvw[index] = Layer(jndex+1);
00150 break;
00151 }
00152
00153
00154 for (jndex=index-1; jndex>=0 ; jndex--) {
00155
00156
00157
00158
00159 if ( iview!=Layer(jndex)->view() ) continue;
00160 _prevlayinvw[index] = Layer(jndex);
00161 break;
00162 }
00163
00164 }
00165 }
00166
00167
00168 void
00169 MdcDetector::buildSuperLayers(void)
00170 {
00171
00172 _nAxSlay = 0;
00173 _nSterSlay[0] = _nSterSlay[1] = 0;
00174
00175
00176
00177 _firstSlayNum = 1;
00178 _lastSlayNum = _nSlay;
00179
00180
00181
00182 _firstSlayInView[0] = _firstSlayInView[1] =_firstSlayInView[2] = 0;
00183 _lastSlayInView[0] = _lastSlayInView[1] =_lastSlayInView[2] = 0;
00184
00185 int islay;
00186
00187
00188 for (islay = 0; islay < _nSlay; islay++) {
00189
00190 MdcSuperLayer* superlay = new MdcSuperLayer(islay);
00191
00192 _slayList[islay] = superlay;
00193 }
00194 _firstSlay = _slayList[0];
00195 _lastSlay = _slayList[_nSlay-1];
00196
00197
00198
00199 for (int lay = 0; lay < _nLayer; lay++) {
00200 int superlayer = lay / _layPerSL;
00201 int index = lay % _layPerSL;
00202 _slayList[superlayer]->addLayer(index,getMdcLayer(lay));
00203 }
00204
00205 MdcSuperLayer* oldSlayByView[3] = {0,0,0};
00206
00207 for (islay = 0; islay < _nSlay; islay++) {
00208 const MdcSuperLayer* prev = 0;
00209 const MdcSuperLayer* next = 0;
00210
00211
00212
00213
00214 int iview = _slayList[islay]->layer(0)->view();
00215 int viewIndex = iview+1;
00216
00217 if ( iview == 0 ) _nAxSlay++;
00218 else if ( iview == -1 ) _nSterSlay[0]++;
00219 else if ( iview == 1 ) _nSterSlay[1]++;
00220
00221
00222 if ( islay > 0 ) prev = _slayList[islay - 1];
00223 if ( islay < _nSlay-1 ) next = _slayList[islay + 1];
00224
00225
00226 if (firstSlayInView(iview) == 0) _firstSlayInView[viewIndex] =
00227 _slayList[islay];
00228 _lastSlayInView[viewIndex] = _slayList[islay];
00229
00230 _slayList[islay]->updateInfo(prev, next);
00231
00232 if (oldSlayByView[viewIndex] != 0) {
00233 oldSlayByView[viewIndex]->setNextInView(_slayList[islay]);
00234 _slayList[islay]->setPrevInView(oldSlayByView[viewIndex]);
00235 }
00236
00237 oldSlayByView[viewIndex] = _slayList[islay];
00238 }
00239 }
00240
00241
00242
00243
00244 const MdcSWire*
00245 MdcDetector::Wire(const Identifier& id) const
00246 {
00247 int wire = MdcID::wire(id);
00248 int layer= MdcID::layer(id);
00249 return Wire(layer, wire);
00250
00251
00252
00253
00254
00255
00256
00257 }
00258
00259 const MdcLayer*
00260 MdcDetector::Layer(const Identifier& id) const
00261 {
00262 unsigned layerid = MdcID::layer(id);
00263 return Layer(layerid);
00264
00265
00266
00267
00268 }
00269