/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/MdcPatRec/MdcGeom/MdcGeom-00-01-17/src/MdcDetector.cxx

Go to the documentation of this file.
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   // build the sense wires
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     //std::cout<< "wire ("<<geowir->Layer()<<","<<geowir->Cell()<<") east "<<eastP <<",west " <<westP << std::endl;//yzhang debug
00057     double sag=0.;
00058     if(_doSag) sag = geowir->Sag()/10.;//mm->cm
00059 
00060     //std::cout<<"sag = "<<sag<<" "<< geowir->Sag()<<std::endl;
00061     _senseWire[iwire] = new MdcSWire(eastP, westP, sag, geowir->Id(), geowir->Cell());
00062 
00063 
00064   }
00065 
00066   // build sense wire layers
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   // build pointers to make navigation faster
00076   buildpointers();
00077 
00078   // do superlayers
00079   // --------------
00080   buildSuperLayers();
00081   // set nominal cell height for each layer!!!! check!!!!
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   // first layers
00119   //  for (int index=0; index<lastLayNum()-firstLayNum()+1; index++) {
00120   for (int index=0; index<_nLayer; index++) {
00121     // initialize
00122     _nextlay[index]=0; _prevlay[index]=0; 
00123     _nextlayinvw[index]=0; _prevlayinvw[index]=0;
00124     //    int layi=index+firstLayNum();
00125 
00126     //    if ( !existDet(layi) ) {
00127     //      ErrMsg(fatal) << " layer # " << layi << " does not exist!" <<endmsg;
00128     //    }
00129     //    _dclayer[index] = dchLayer(layi);
00130 
00131     //next and previous pointers
00132     //    if (existDet(layi+1)) { _nextlay[index] = dchLayer(layi+1); }
00133     //    if (existDet(layi-1)) { _prevlay[index] = _dclayer[index-1]; }
00134 
00135     if ( index + 1 < _nLayer ) { _nextlay[index] = Layer(index+1); }
00136     if ( index > 0                  ) { _prevlay[index] = Layer(index-1); }
00137 
00138     //next in view pointer
00139     //    int iview=dchLayer(layi)->view();
00140     int iview = Layer(index)->view();
00141     int jndex;
00142     //    for (jndex=index+1; jndex<lastLayNum()-firstLayNum()+1; jndex++) {
00143     for (jndex=index+1; jndex<_nLayer; jndex++) {
00144       //      int layj=jndex+firstLayNum();
00145       //      if ( !existDet(layj) ) {
00146       //        ErrMsg(fatal) << " layer # " << layj << " does not exist!" <<endmsg;
00147       //      }
00148       if ( iview != Layer(jndex)->view() ) continue;
00149       _nextlayinvw[index] = Layer(jndex+1);
00150       break;
00151     } //(int jndex=index+1; _dclayer[jndex].Exist(); jndex++) 
00152 
00153     //prev in view pointer
00154     for (jndex=index-1; jndex>=0 ; jndex--) {
00155       //      int layj=jndex+firstLayNum();
00156       //      if ( !existDet(layj) ) {
00157       //        ErrMsg(fatal) << " layer # " << layj << " does not exist!" <<endmsg;
00158       //      }
00159       if ( iview!=Layer(jndex)->view() ) continue;
00160       _prevlayinvw[index] = Layer(jndex);
00161       break;
00162     } //(int jndex=index+1; _dclayer[jndex].exist(); jndex++) 
00163 
00164   } //(int index=0; _dclayer[index].exist(); index++)
00165   }
00166 
00167 
00168   void 
00169     MdcDetector::buildSuperLayers(void) 
00170     {
00171       // some initializations
00172       _nAxSlay = 0;
00173       _nSterSlay[0] = _nSterSlay[1] = 0;
00174 
00175       //  _nSlay = _nLayer/_layPerSL;
00176 
00177       _firstSlayNum = 1;
00178       _lastSlayNum = _nSlay;
00179       //  _slayList = new MdcSuperLayer*[_nSlay];
00180 
00181       // initialize pointers 
00182       _firstSlayInView[0] = _firstSlayInView[1] =_firstSlayInView[2] = 0;
00183       _lastSlayInView[0] = _lastSlayInView[1] =_lastSlayInView[2] = 0;
00184 
00185       int islay;
00186 
00187       // build the SuperLayers
00188       for (islay = 0; islay < _nSlay; islay++) {
00189         //    MdcSuperLayer* superlay = new MdcSuperLayer("Dch SuperLayer",1001+islay);
00190         MdcSuperLayer* superlay = new MdcSuperLayer(islay);
00191         //    *_dchslayerset += *superlay;
00192         _slayList[islay] = superlay;
00193       } 
00194       _firstSlay = _slayList[0];
00195       _lastSlay = _slayList[_nSlay-1];
00196 
00197       // set pointers to Layers in SuperLayers
00198       //  for (int lay=firstLayNum(); lay<=lastLayNum(); lay++) {
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       // update SuperLayer data members
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         //    const MdcSuperLayer* prevInView = 0;
00211         //    const MdcSuperLayer* nextInView = 0;
00212 
00213         // SuperLayer view
00214         int iview = _slayList[islay]->layer(0)->view();
00215         int viewIndex = iview+1;
00216         // count SuperLayer types
00217         if ( iview == 0 ) _nAxSlay++;
00218         else if ( iview == -1 ) _nSterSlay[0]++;
00219         else if ( iview == 1 ) _nSterSlay[1]++;
00220 
00221         // build pointer links
00222         if ( islay > 0 ) prev = _slayList[islay - 1];
00223         if ( islay < _nSlay-1 ) next = _slayList[islay + 1];
00224 
00225         // fill first and last SuperLayer pointers
00226         if (firstSlayInView(iview) == 0) _firstSlayInView[viewIndex] =
00227           _slayList[islay];
00228         _lastSlayInView[viewIndex] = _slayList[islay];
00229 
00230         _slayList[islay]->updateInfo(prev, next);
00231         // now the poiters to SuperLayers of the same view
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         //  unsigned wireid= Layer(layer)->Wirst()+wire;
00251         //  if( wireid < fWires.size()){
00252         //          return fWires[wireid];
00253         //  }
00254         //  else {
00255         //  return 0;
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         //  if (layerid < fLayers.size())
00265         //         return fLayers[layerid];
00266         //
00267         //         return 0;
00268       }
00269 

Generated on Tue Nov 29 23:13:30 2016 for BOSS_7.0.2 by  doxygen 1.4.7