/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/TrkReco/TrkReco-00-08-59-patch4-slc6tag/src/TMDC.cxx

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 // $Id: TMDC.cxx,v 1.16 2012/05/28 05:16:29 maoh Exp $
00003 //-----------------------------------------------------------------------------
00004 // Filename : TMDC.cc
00005 // Section  : Tracking MDC
00006 // Owner    : Yoshi Iwasaki
00007 // Email    : yoshihito.iwasaki@kek.jp
00008 //-----------------------------------------------------------------------------
00009 // Description : A class to represent MDC.
00010 //               See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
00011 //-----------------------------------------------------------------------------
00012 
00013 #ifdef TRKRECO_DEBUG_DETAIL
00014 #ifndef TRKRECO_DEBUG
00015 #define TRKRECO_DEBUG
00016 #endif
00017 #endif
00018 #include <iostream>
00019 #include "CLHEP/String/Strings.h"
00020 //#include "belle.h"
00021 #include "TrkReco/TMDC.h"
00022 #include "TrkReco/TMDCUtil.h"
00023 #include "TrkReco/TMDCWire.h"
00024 #include "TrkReco/TMDCLayer.h"
00025 #include "TrkReco/TMDCWireHit.h"
00026 #include "TrkReco/TMDCWireHitMC.h"
00027 #include "TrkReco/TMLink.h"
00028 #include "TrkReco/TTrack.h"
00029 #include "TrkReco/TTrackHEP.h"
00030 //#include MDC_H
00031 //#include BELLETDF_H
00032 //#include "MdcRecGeo/MdcRecGeo.h"
00033 #include "MdcGeomSvc/MdcGeomSvc.h"
00034 #include "MdcTables/MdcTables.h"
00035 //#include "tables/bestdf.h"
00036 
00037 //#include "GaudiKernel/Algorithm.h"
00038 #include "GaudiKernel/MsgStream.h"
00039 #include "GaudiKernel/AlgFactory.h"
00040 #include "GaudiKernel/ISvcLocator.h"
00041 #include "GaudiKernel/IMessageSvc.h"
00042 #include "GaudiKernel/IDataProviderSvc.h"
00043 #include "GaudiKernel/SmartDataPtr.h"
00044 #include "GaudiKernel/PropertyMgr.h"
00045 #include "GaudiKernel/IJobOptionsSvc.h"
00046 #include "GaudiKernel/Bootstrap.h"
00047 #include "GaudiKernel/StatusCode.h"
00048 #include "EventModel/Event.h"
00049 //#include "MDCRawEvent/MdcDigi.h"
00050 //#include "TOFRawEvent/TofDigi.h"
00051 //#include "EMCRawEvent/CalDigi.h"
00052 //#include "McTruth/McKine.h"
00053  
00054 #include <vector>
00055 #include <iostream>
00056  
00057 using namespace std;
00058 using namespace Event;
00059 
00060 TMDC * GMDC = 0;
00061 /*zsl
00062 extern "C" {
00063     void calcdc_driftdist_(int *,
00064                            int *,
00065                            int *,
00066                            float[3],
00067                            float[3],
00068                            float *,
00069                            float *,
00070                            float *);
00071     void calcdc_tof2_(int *, float *, float *, float *);
00072 };
00073 */
00074 
00075 std::string
00076 TMDC::name(void) const {
00077     return "TMDC";
00078 }
00079 
00080 std::string
00081 TMDC::version(void) const {
00082     return "2.18";
00083 }
00084 
00085 TMDC *
00086 TMDC::_cdc = 0;
00087 
00088 TMDC *
00089 TMDC::getTMDC(const std::string & version) {
00090     if (! _cdc) _cdc = new TMDC(version);
00091     return _cdc;
00092 }
00093 
00094 TMDC *
00095 TMDC::getTMDC(void) {
00096     if (! _cdc) _cdc = new TMDC("1.0");
00097     return _cdc;
00098 }
00099 
00100 TMDC::TMDC(const std::string & version) 
00101 : _debugLevel(0),
00102   _fudgeFactor(1.),
00103   _cdcVersion(version), 
00104 //  _cdcVersion(-2000),
00105 //  _nWires(BsCouTab(GEOMDC_WIRE)),
00106 //  _nSuperLayers(BsCouTab(GEOMDC_SUPER)),
00107 //  _nLayers(BsCouTab(GEOMDC_LAYER)),
00108 //  _geo(MdcRecGeo::getMdcRecGeo()),
00109 //  _nWires(_geo->getWireSize()),
00110 //  _nSuperLayers(_geo->getSuperLayerSize()),
00111 //  _nLayers(_geo->getLayerSize()),
00112   _nWires(6796),
00113   _nSuperLayers(11),
00114   _nLayers(43),
00115   _newCdc(version == "-2000") {
00116     
00117     GMDC = this;
00118 
00119     //...Get MDC information...
00120     std::cout << "TMDC ... MDC version = " << _cdcVersion << std::endl;
00121 
00122     //...Check GEOMDC_WIRE...
00123 /*    if (BsCouTab(GEOMDC_LAYER) == 0) {
00124         std::cout << "TMDC !!! Bank GEOMDC_LAYER not found" << std::endl;
00125         std::cout << "     !!! mission impossible" << std::endl;
00126         std::cout << "     !!! TrkReco will crash!" << std::endl;
00127         std::cout << "     !!! Please stop execution" << std::endl;
00128         return;
00129     }
00130 */
00131 
00132   IMdcGeomSvc* mdcGeomSvc;
00133   StatusCode sc = Gaudi::svcLocator()->service("MdcGeomSvc", mdcGeomSvc);
00134   if (sc ==  StatusCode::SUCCESS) {
00135 //   mdcGeomSvc->Dump();
00136     
00137 //   _nWires = mdcGeomSvc->getWireSize();
00138 //   _nSuperLayers = mdcGeomSvc->getSuperLayerSize();
00139 //   _nLayers = mdcGeomSvc->getLayerSize();
00140    
00141     //...Create super-layers...
00142     for (unsigned i = 0; i < _nSuperLayers; i++)
00143         _superLayers.append(new AList<TMDCLayer>);
00144 
00145     //...Loop over all wires layers...
00146     unsigned nWires = 0;
00147     for (unsigned i = 0; i < _nLayers; i++) {
00148 //      struct geocdc_layer * l =
00149 //          (struct geocdc_layer *)
00150 //          BsGetEnt(GEOMDC_LAYER, i + 1, BBS_No_Index);
00151             
00152         const MdcGeoLayer * l = mdcGeomSvc->Layer(i);
00153         TMDCLayer * layer =  new TMDCLayer(l);
00154         _layers.append(layer);
00155         _superLayers[layer->superLayerId()]->append(layer);
00156 
00157         //...Loop over all wires in a layer...
00158         for (unsigned j = 0; j < l->NCell(); j++) {
00159 //      for (unsigned j = 0; j < l->m_div; j++) {
00160 //          struct geocdc_wire * w =
00161 //              (struct geocdc_wire *)
00162 //              BsGetEnt(GEOMDC_WIRE, nWires + 1, BBS_No_Index);
00163             const MdcGeoWire * w = mdcGeomSvc->Wire(l->Wirst()+j);
00164             TMDCWire * tw = new TMDCWire(w, layer);
00165             _wires.append(tw);
00166             layer->append(tw);
00167 
00168             ++nWires;
00169         }
00170     }
00171 
00172   } else {
00173 //    return StatusCode::FAILURE;
00174     return;
00175   }
00176  
00177 //  return StatusCode::SUCCESS;
00178 }
00179 
00180 void
00181 TMDC::dump(const std::string & msg) const {
00182 //      if (   msg.index("name")    != -1
00183 //      || msg.index("version") != -1
00184 //      || msg.index("detail")  != -1
00185 //      || msg == "") {
00186   if (   msg.find("name")    != std::string::npos
00187         || msg.find("version") != std::string::npos
00188         || msg.find("detail")  != std::string::npos
00189         || msg == "") {
00190         std::cout << name() << "(" << version() << ") ";
00191     }
00192     if (msg.find("detail") != std::string::npos || msg.find("state") != std::string::npos) {
00193         std::cout << "Debug Level=" << _debugLevel;
00194     }
00195     std::cout << std::endl;
00196 
00197     std::string tab("        ");
00198 
00199     if (msg == "" || msg.find("geometry") != std::string::npos) {
00200 
00201         //...Get information..."
00202         unsigned nLayer = _layers.length();
00203         std::cout << "    version    : " << version() << std::endl;
00204         std::cout << "    cdc version: " << cdcVersion() << std::endl;
00205         std::cout << "    # of wires : " << _wires.length() << std::endl;
00206         std::cout << "    # of layers: " << nLayer << std::endl;
00207         std::cout << "    super layer information" << std::endl;
00208         std::cout << "        # of super layers = " << _superLayers.length()
00209                   << std::endl;
00210 
00211         std::cout << "    layer information" << std::endl;
00212         for (unsigned i = 0; i < _nLayers; i++)
00213             _layers[i]->dump("", tab);
00214 
00215         std::cout << "    wire information" << std::endl;
00216         for (unsigned i = 0; i < _nWires; i++)
00217             (_wires[i])->dump("neighbor", tab);
00218 
00219         return;
00220     }
00221     if (msg.find("hits") != std::string::npos) {
00222         std::cout << "    hits     : " << _hits.length() << std::endl;
00223         for (unsigned i = 0; i < _hits.length(); i++) {
00224             _hits[i]->dump("state mc", tab);
00225         }
00226     }
00227     if (msg.find("axialHits") != std::string::npos) {
00228         std::cout << "    hits     : " << _axialHits.length() << std::endl;
00229         for (unsigned i = 0; i < _axialHits.length(); i++) {
00230             _axialHits[i]->dump("state mc", tab);
00231         }
00232     }
00233     if (msg.find("stereoHits") != std::string::npos) {
00234         std::cout << "    hits     : " << _stereoHits.length() << std::endl;
00235         for (unsigned i = 0; i < _stereoHits.length(); i++) {
00236             _stereoHits[i]->dump("state mc", tab);
00237         }
00238     }
00239 }
00240 
00241 const TMDCWire * const
00242 TMDC::wire(unsigned layerId, int localId) const {
00243     if (layerId < _nLayers)
00244         return _layers[layerId]->wire(localId);
00245 
00246     return NULL;
00247 }
00248 
00249 const TMDCWire * const
00250 TMDC::wire(const HepPoint3D & p) const {
00251     float r = p.mag();
00252     float phi = p.phi();
00253     return wire(r, phi);
00254 }
00255 
00256 const TMDCWire * const
00257 TMDC::wire(float r, float p) const {
00258 
00259     std::cout << "r,phi = " << r << "," << p << std::endl;
00260 
00261     unsigned id = 25;
00262     bool ok = false;
00263     const TMDCLayer * l;
00264     while (! ok) {
00265         l = layer(id);
00266         if (! l) return NULL;
00267         
00268         const MdcGeoLayer * geo = l->geocdc();
00269         if (geo->Radius()/10 + geo->RCSiz2()/10 < r) ++id;
00270         else if (geo->Radius()/10 - geo->RCSiz1()/10 > r) --id;
00271         else ok = true;
00272     }
00273 //    float dPhi = 2. * M_PI / float(l->nWires());
00274 //    if (l->geocdc()->m_offset > 0.) p -= dPhi / 2.;
00275     float dPhi = 2. * M_PI / float(l->nWires());   
00276     p -= l->geocdc()->Offset()/dPhi; 
00277     unsigned localId = unsigned(phi(p) / dPhi);
00278     return l->wire(localId);
00279 }
00280 
00281 void
00282 TMDC::clear(void) {
00283     unsigned i = 0;
00284     while (TMDCWire * w = _wires[i++])
00285         w->clear();
00286 
00287     _hitWires.removeAll();
00288     _axialHits.removeAll();
00289     _stereoHits.removeAll();
00290     HepAListDeleteAll(_hits);
00291     HepAListDeleteAll(_hitsMC);
00292     HepAListDeleteAll(_badHits);
00293 
00294     TUpdater::clear();
00295 }
00296 
00297 void
00298 TMDC::fastClear(void) {
00299     unsigned i = 0;
00300     while (TMDCWire * w = _hitWires[i++])
00301         w->clear();
00302     i = 0;
00303     while (TMDCWireHit * h = _badHits[i++])
00304         ((TMDCWire *) h->wire())->clear();
00305 
00306     _hitWires.removeAll();
00307     _axialHits.removeAll();
00308     _stereoHits.removeAll();
00309     HepAListDeleteAll(_hits);
00310     HepAListDeleteAll(_hitsMC);
00311     HepAListDeleteAll(_badHits);
00312 
00313     TUpdater::clear();
00314 }
00315 
00316 void
00317 TMDC::update(bool mcAnalysis) {
00318     //...Already updated?...
00319 //zsl    if (updated()) return;
00320 
00321     //...Clear old information...
00322     fastClear();
00323 
00324     //...Loop over RECMDC_WIRHIT bank...
00325 //    unsigned nReccdc = BsCouTab(RECMDC_WIRHIT);
00326      unsigned nReccdc = MdcRecWirhitCol::getMdcRecWirhitCol()->size();
00327 #ifdef TRKRECO_DEBUG
00328     cout<<"size of MdcRecWirhit:"<<nReccdc<<endl;   
00329 #endif
00330     for (unsigned i = 0; i < nReccdc; i++) {
00331 //      struct reccdc_wirhit * h =
00332 //          (struct reccdc_wirhit *)
00333 //          BsGetEnt(RECMDC_WIRHIT, i + 1, BBS_No_Index);
00334         MdcRec_wirhit* h = &(*MdcRecWirhitCol::getMdcRecWirhitCol())[i]; 
00335         //...Check validity...
00336 //zsl   if (! (h->stat & WireHitFindingValid)) continue;
00337 
00338         //...Obtain a pointer to GEOMDC...
00339 //      struct geocdc_wire * g =
00340 //          (struct geocdc_wire *)
00341 //          BsGetEnt(GEOMDC_WIRE, h->m_geo, BBS_No_Index);
00342         const MdcGeoWire* g = h->geo;
00343 //      if (_newCdc)
00344 //          if (g->m_ID < 256)
00345 //              continue;
00346 
00347         //...Get a pointer to a TMDCWire...
00348 //      TMDCWire * w = _wires[g->m_ID - 1];
00349         TMDCWire * w = _wires[g->Id()];   
00350         _hitWires.append(w);
00351 
00352         //...Create TMDCWireHit...
00353         TMDCWireHit * hit = new TMDCWireHit(w, h, _fudgeFactor);
00354         _hits.append(hit);
00355 
00356         //... update the wirehit pointer in the TMDCWire  (by zang shilei)
00357         w->hit(hit);
00358        //if (w->hit()) cout<<"test .......... right~~~~~"<<endl; 
00359         
00360         //...Axial or stereo...
00361         if (w->axial()) _axialHits.append(hit);
00362         else            _stereoHits.append(hit);
00363     }
00364             
00365     //...Hit classfication...
00366     classification();
00367 
00368     //...MC information...
00369     if (mcAnalysis) updateMC();
00370 
00371     //...Update information...
00372     TUpdater::update();
00373 }
00374 
00375 void
00376 TMDC::updateMC(void) {
00377 
00378     //...Create TTrackHEP...
00379     TTrackHEP::update();
00380 
00381     //...Loop over DATMDC_MCWIRHIT bank...
00382     unsigned n = 0;
00383 //    for (unsigned i = 0; i < BsCouTab(DATMDC_MCWIRHIT); i++) {
00384     for (unsigned i = 0; i < MdcDatMcwirhitCol::getMdcDatMcwirhitCol()->size(); i++) {   
00385 //        struct datcdc_mcwirhit * h =
00386 //          (struct datcdc_mcwirhit *)
00387 //          BsGetEnt(DATMDC_MCWIRHIT, i + 1, BBS_No_Index);
00388         MdcDat_mcwirhit* h = &(*MdcDatMcwirhitCol::getMdcDatMcwirhitCol())[i];
00389         //...Get a pointer to RECMDC_WIRHIT...
00390 //      reccdc_wirhit * whp =
00391 //          (reccdc_wirhit *) BsGetEnt(RECMDC_WIRHIT, h->m_dat, BBS_No_Index);
00392         MdcRec_wirhit* whp = h->dat->rec;
00393         //...Get TrkReco objects...
00394         TMDCWireHit * wh = 0;
00395         TMDCWire * w = 0;
00396         if (whp) {
00397             if (whp->stat & WireHitFindingValid) {
00398                 unsigned n = _hits.length();
00399                 unsigned j = (whp->id < n) ? whp->id : n;
00400                 while (j) {
00401                     --j;
00402                     if (_hits[j]->reccdc() == whp) {
00403                         wh = _hits[j];
00404                         w = _wires[wh->wire()->id()];
00405                         break;
00406                     }
00407                 }
00408             }
00409         }
00410         if (! w) {
00411 //          geocdc_wire * g =
00412 //              (geocdc_wire *) BsGetEnt(GEOMDC_WIRE, h->m_geo, BBS_No_Index);
00413 //          w = _wires[g->m_ID - 1];
00414           const MdcGeoWire* g = h->geo;
00415         }
00416 
00417         //...Create TMDCWireHitMC...
00418         TMDCWireHitMC * hit = new TMDCWireHitMC(w, wh, h);
00419         _hitsMC.append(hit);
00420         w->hit(hit);
00421         if (wh) wh->mc(hit);
00422 
00423         //...TTrackHEP...
00424 //      TTrackHEP * hep = TTrackHEP::list()[h->m_hep - 1];
00425         TTrackHEP * hep = TTrackHEP::list()[h->hep->id];     
00426         hit->_hep = hep;
00427         if (hep) hep->_hits.append(hit);
00428         else {
00429             std::cout << "TMDC::updateMC !!! mission impossible" << std::endl;
00430             std::cout << "                   This error will cause TrkReco crush";
00431             std::cout << std::endl;
00432 #ifdef TRKRECO_DEBUG_DETAIL
00433             //cout << "    h->m_hep, h->m_hep -1 = " << h->m_hep;
00434             //std::cout << ", " << h->m_hep - 1 << std::endl;
00435             std::cout << "    TTrackHEP list length = ";
00436             std::cout << TTrackHEP::list().length() << std::endl;
00437 //          BsShwDat(GEN_HEPEVT);
00438 //          BsShwDat(DATMDC_MCWIRHIT);
00439 #endif
00440         }
00441     }
00442 }
00443 
00444 void
00445 TMDC::classification(void) {
00446     unsigned n = _hits.length();
00447 
00448     for (unsigned i = 0; i < n; i++) {
00449         TMDCWireHit * h = _hits[i];
00450         const TMDCWire * w = h->wire();
00451         unsigned state = h->state();
00452 
00453         //...Cache pointers to a neighbor...
00454         const TMDCWire * neighbor[6];
00455         for (unsigned j = 0; j < 6; j++) neighbor[j] = w->neighbor(j);
00456 
00457         //output to test ...
00458 //      cout<<w->localId()<<endl;
00459 //      if(neighbor[0]) cout<<"inner local:"<<neighbor[0]->localId()<<", "<<neighbor[1]->localId()<<endl;
00460 //      if(neighbor[5]) cout<<"outer local:"<<neighbor[4]->localId()<<", "<<neighbor[5]->localId()<<endl;   
00461                 
00462         //...Decide hit pattern...
00463         unsigned pattern = 0;
00464         for (unsigned j = 0; j < 6; j++) {
00465             if (neighbor[j])
00466                 if (neighbor[j]->hit())
00467                     pattern += (1 << j);
00468         }
00469         state |= (pattern << WireHitNeighborHit);
00470 
00471         //...Check isolation...
00472         const TMDCWireHit * hr1 = neighbor[2]->hit();
00473         const TMDCWireHit * hl1 = neighbor[3]->hit();
00474         if ((hr1 == 0) && (hl1 == 0)) {
00475             state |= WireHitIsolated;
00476         }
00477         else {
00478             const TMDCWireHit * hr2 = neighbor[2]->neighbor(2)->hit();
00479             const TMDCWireHit * hl2 = neighbor[3]->neighbor(3)->hit();
00480             if ((hr2 == 0) && (hr1 != 0) && (hl1 == 0) ||
00481                 (hl2 == 0) && (hl1 != 0) && (hr1 == 0))
00482                 state |= WireHitIsolated;
00483         }
00484 
00485         //...Check continuation...
00486         unsigned superLayer = w->superLayerId();
00487         bool previous = false;
00488         bool next = false;
00489         if (neighbor[0] == 0) previous = true;
00490         else {
00491             if ((neighbor[0]->hit()) || neighbor[1]->hit())
00492                 previous = true;
00493         }
00494         if (neighbor[5] == 0) next = true;
00495         else {
00496             if ((neighbor[4]->hit()) || neighbor[5]->hit())
00497                 next = true;
00498         }
00499         // if (previous && next) state |= WireHitContinuous;
00500         if (previous || next) state |= WireHitContinuous;
00501 
00502         //...Solve LR locally...
00503         if ((pattern == 34) || (pattern == 42) ||
00504             (pattern == 40) || (pattern == 10) ||
00505             (pattern == 35) || (pattern == 50))
00506             state |= WireHitPatternRight;
00507         else if ((pattern == 17) || (pattern == 21) ||
00508                  (pattern == 20) || (pattern ==  5) ||
00509                  (pattern == 19) || (pattern == 49))
00510             state |= WireHitPatternLeft;
00511 
00512         //...Store it...
00513         h->state(state);
00514     }
00515 }
00516 
00517 const AList<TMDCWireHit> &
00518 TMDC::axialHits(unsigned mask) const {
00519     if (! mask) return _axialHits;
00520     else if (mask == WireHitFindingValid) return _axialHits;
00521     std::cout << "TMDC::axialHits !!! unsupported mask given" << std::endl;
00522     return _axialHits;
00523 }
00524 
00525 const AList<TMDCWireHit> &
00526 TMDC::stereoHits(unsigned mask) const {
00527     if (! mask) return _stereoHits;
00528     else if (mask == WireHitFindingValid) return _stereoHits;
00529     std::cout << "TMDC::stereoHits !!! unsupported mask given" << std::endl;
00530     return _stereoHits;
00531 }
00532 
00533 const AList<TMDCWireHit> &
00534 TMDC::hits(unsigned mask) const {
00535     if (! mask) return _hits;
00536     else if (mask == WireHitFindingValid) return _hits;
00537     std::cout << "TMDC::hits !!! unsupported mask given" << std::endl;
00538     return _hits;
00539 }
00540 
00541 const AList<TMDCWireHit> &
00542 TMDC::badHits(void) {
00543     if (! updated()) update();
00544     if (_badHits.length()) return _badHits;
00545 
00546     //...Loop over RECMDC_WIRHIT bank...
00547 //    unsigned nReccdc = BsCouTab(RECMDC_WIRHIT);
00548     unsigned nReccdc = MdcRecWirhitCol::getMdcRecWirhitCol()->size();
00549     for (unsigned i = 0; i < nReccdc; i++) {
00550 //      struct reccdc_wirhit * h =
00551 //          (struct reccdc_wirhit *)
00552 //          BsGetEnt(RECMDC_WIRHIT, i + 1, BBS_No_Index);
00553         MdcRec_wirhit* h = &(*MdcRecWirhitCol::getMdcRecWirhitCol())[i];
00554         
00555         //...Check validity...
00556         if (h->stat & WireHitFindingValid) continue;
00557 
00558         //...Obtain a pointer to GEOMDC...
00559 //      geocdc_wire * g =
00560 //          (geocdc_wire *) BsGetEnt(GEOMDC_WIRE, h->m_geo, BBS_No_Index);
00561         const MdcGeoWire* g = h->geo;
00562         
00563         //...Get a pointer to a TMDCWire...
00564 //      TMDCWire * w = _wires[g->m_ID - 1];
00565         TMDCWire * w = _wires[g->Id()];
00566         
00567         //...Create TMDCWireHit...
00568         _badHits.append(new TMDCWireHit(w, h, _fudgeFactor));
00569     }
00570 
00571     return _badHits;
00572 }
00573 
00574 std::string
00575 TMDC::wireName(unsigned wireId) {
00576     if (superLayerId(wireId) % 2)
00577         return itostring(layerId(wireId)) + "=" +
00578             itostring(localId(wireId));
00579     return itostring(layerId(wireId)) + "-" + itostring(localId(wireId));
00580 }
00581 
00582 std::string
00583 TMDC::wireName(const MdcGeoWire * const w) {
00584     if (! w) return std::string("no such a wire");
00585 //    unsigned id = w->m_ID - 1;
00586     unsigned id = w->Id();
00587     return wireName(id);
00588 }
00589 
00590 //std::string
00591 //TMDC::wireName(const Geocdc_wire * const w) {
00592 //    if (! w) return std::string("no such a wire");
00593 //    unsigned id = w->get_ID() - 1;
00594 //    return wireName(id);
00595 //}
00596 
00597 unsigned
00598 TMDC::layerId(unsigned id) {
00599 //    int length = _wires.length();
00600 //    if(id < length) return _wires[id]->geocdc()->Layer();
00601 //    return 9999;    
00602 
00603     if (id < 40) return 0;
00604     else if (id < 84) return 1;
00605     else if (id < 132) return 2;
00606     else if (id < 188) return 3;
00607 
00608     else if (id < 252) return 4;
00609     else if (id < 324) return 5;
00610     else if (id < 404) return 6;
00611     else if (id < 484) return 7;
00612 
00613     else if (id < 560) return 8;
00614     else if (id < 636) return 9;
00615     else if (id < 724) return 10;
00616     else if (id < 812) return 11;
00617 
00618     else if (id < 912) return 12;
00619     else if (id < 1012) return 13;
00620     else if (id < 1124) return 14;
00621     else if (id < 1236) return 15;
00622 
00623     else if (id < 1364) return 16;
00624     else if (id < 1492) return 17;
00625     else if (id < 1632) return 18;
00626     else if (id < 1772) return 19;
00627 
00628     else if (id < 1932) return 20;
00629     else if (id < 2092) return 21;
00630     else if (id < 2252) return 22;
00631     else if (id < 2412) return 23;
00632 
00633     else if (id < 2604) return 24;
00634     else if (id < 2796) return 25;
00635     else if (id < 2988) return 26;
00636     else if (id < 3180) return 27;
00637 
00638     else if (id < 3388) return 28;
00639     else if (id < 3596) return 29;
00640     else if (id < 3804) return 30;
00641     else if (id < 4012) return 31;
00642 
00643     else if (id < 4252) return 32;
00644     else if (id < 4492) return 33;
00645     else if (id < 4732) return 34;
00646     else if (id < 4972) return 35;
00647 
00648     else if (id < 5228) return 36;
00649     else if (id < 5484) return 37;
00650     else if (id < 5740) return 38;
00651     else if (id < 5996) return 39;
00652 
00653     else if (id < 6284) return 40;
00654     else if (id < 6572) return 41;
00655     else if (id < 6860) return 42;
00656 
00657     return 9999;    
00658 }
00659 
00660 unsigned
00661 TMDC::layerId(const MdcGeoWire * const w) {
00662     if (! w) return 9999;
00663     //zsl    unsigned id = w->Id();
00664     //    return layerId(id);
00665     return w->Layer();
00666 }
00667 
00668 //unsigned
00669 //TMDC::layerId(const Geocdc_wire * const w) {
00670 //    if (! w) return 9999;
00671 //    unsigned id = w->get_ID() - 1;
00672 //    return layerId(id);
00673 //}
00674 
00675 unsigned
00676 TMDC::localId(unsigned id) {
00677     if (id < 40) return id;
00678     else if (id < 84) return id-40;
00679     else if (id < 132) return id-84;
00680     else if (id < 188) return id-132;
00681 
00682     else if (id < 252) return id-188;
00683     else if (id < 324) return id-252;
00684     else if (id < 404) return id-324;
00685     else if (id < 484) return id-404;
00686 
00687     else if (id < 560) return id-484;
00688     else if (id < 636) return id-560;
00689     else if (id < 724) return id-636;
00690     else if (id < 812) return id-724;
00691 
00692     else if (id < 912) return id-812;
00693     else if (id < 1012) return id-912;
00694     else if (id < 1124) return id-1012;
00695     else if (id < 1236) return id-1124;
00696 
00697     else if (id < 1364) return id-1236;
00698     else if (id < 1492) return id-1364;
00699     else if (id < 1632) return id-1492;
00700     else if (id < 1772) return id-1632;
00701 
00702     else if (id < 1932) return id-1772;
00703     else if (id < 2092) return id-1932;
00704     else if (id < 2252) return id-2092;
00705     else if (id < 2412) return id-2252;
00706 
00707     else if (id < 2604) return id-2412;
00708     else if (id < 2796) return id-2604;
00709     else if (id < 2988) return id-2796;
00710     else if (id < 3180) return id-2988;
00711 
00712     else if (id < 3388) return id-3180;
00713     else if (id < 3596) return id-3388;
00714     else if (id < 3804) return id-3596;
00715     else if (id < 4012) return id-3804;
00716 
00717     else if (id < 4252) return id-4012;
00718     else if (id < 4492) return id-4252;
00719     else if (id < 4732) return id-4492;
00720     else if (id < 4972) return id-4732;
00721 
00722     else if (id < 5228) return id-4972;
00723     else if (id < 5484) return id-5228;
00724     else if (id < 5740) return id-5484;
00725     else if (id < 5996) return id-5740;
00726 
00727     else if (id < 6284) return id-5996;
00728     else if (id < 6572) return id-6284;
00729     else if (id < 6860) return id-6572;
00730 
00731     return 9999;    
00732  
00733 /*    if (id < 384) return id % 64;
00734     else if (id < 624) return (id - 384) % 80;
00735     else if (id < 1200) return (id - 624) % 96;
00736     else if (id < 1584) return (id - 1200) % 128;
00737     else if (id < 2304) return (id - 1584) % 144;
00738     else if (id < 2944) return (id - 2304) % 160;
00739     else if (id < 3904) return (id - 2944) % 176;
00740     else if (id < 4736) return (id - 3904) % 208;
00741     else if (id < 5936) return (id - 4736) % 240;
00742     else if (id < 6960) return (id - 5936) % 256;
00743     else if (id < 8400) return (id - 6960) % 288;
00744 
00745     return 9999;
00746 */
00747 }
00748 
00749 unsigned
00750 TMDC::localId(const MdcGeoWire * const w) {
00751     if (! w) return 9999;
00752 //    unsigned id = w->Id();
00753 //    return localId(id);
00754     return w->Cell();    
00755 }
00756 
00757 //unsigned
00758 //TMDC::localId(const Geocdc_wire * const w) {
00759 //    if (! w) return 9999;
00760 //    unsigned id = w->get_ID() - 1;
00761 //    return localId(id);
00762 //}
00763 
00764 unsigned
00765 TMDC::superLayerId(unsigned id) {
00766     if (id < 188) return 0;
00767     else if (id < 484) return 1;
00768     else if (id < 812) return 2;
00769     else if (id < 1236) return 3;
00770     else if (id < 1772) return 4;
00771     else if (id < 2412) return 5;
00772     else if (id < 3180) return 6;
00773     else if (id < 4012) return 7;
00774     else if (id < 4972) return 8;
00775     else if (id < 5996) return 9;
00776     else if (id < 6860) return 10;
00777  
00778     return 9999;    
00779 /*    if (id < 384) return 0;
00780     else if (id < 624) return 1;
00781     else if (id < 1200) return 2;
00782     else if (id < 1584) return 3;
00783     else if (id < 2304) return 4;
00784     else if (id < 2944) return 5;
00785     else if (id < 3904) return 6;
00786     else if (id < 4736) return 7;
00787     else if (id < 5936) return 8;
00788     else if (id < 6960) return 9;
00789     else if (id < 8400) return 10;
00790 
00791     return 9999;
00792 */
00793 }
00794 
00795 unsigned
00796 TMDC::superLayerId(const MdcGeoWire * const w) {
00797     if (! w) return 9999;
00798     unsigned id = w->Id();
00799     return superLayerId(id);
00800 }
00801 
00802 //unsigned
00803 //TMDC::superLayerId(const Geocdc_wire * const w) {
00804 //    if (! w) return 9999;
00805 //    unsigned id = w->get_ID() - 1;
00806 //    return superLayerId(id);
00807 //}
00808 
00809 unsigned
00810 TMDC::superLayerId(const MdcGeoLayer * const l) {
00811     if (! l) return 9999;
00812     unsigned id = l->Id();
00813 
00814     if(id < 44) return id/4;
00815     return 9999;     
00816 /*    if (id < 6) return 0;
00817     else if (id < 9) return 1;
00818     else if (id < 15) return 2;
00819     else if (id < 18) return 3;
00820     else if (id < 23) return 4;
00821     else if (id < 27) return 5;
00822     else if (id < 32) return 6;
00823     else if (id < 36) return 7;
00824     else if (id < 41) return 8;
00825     else if (id < 45) return 9;
00826     else if (id < 50) return 10;
00827 
00828     return 9999;
00829 */
00830 }
00831 
00832 unsigned
00833 TMDC::localLayerId(unsigned id) {
00834     if(id < 6860) return layerId(id)%4;
00835     return 9999;
00836     
00837 /*    if (id < 64) return 0;
00838     else if (id < 128) return 1;
00839     else if (id < 192) return 2;
00840     else if (id < 256) return 3;
00841     else if (id < 320) return 4;
00842     else if (id < 384) return 5;
00843 
00844     else if (id < 464) return 0;
00845     else if (id < 544) return 1;
00846     else if (id < 624) return 2;
00847 
00848     else if (id < 720) return 0;
00849     else if (id < 816) return 1;
00850     else if (id < 912) return 2;
00851     else if (id < 1008) return 3;
00852     else if (id < 1104) return 4;
00853     else if (id < 1200) return 5;
00854 
00855     else if (id < 1328) return 0;
00856     else if (id < 1456) return 1;
00857     else if (id < 1584) return 2;
00858 
00859     else if (id < 1728) return 0;
00860     else if (id < 1872) return 1;
00861     else if (id < 2016) return 2;
00862     else if (id < 2160) return 3;
00863     else if (id < 2304) return 4;
00864 
00865     else if (id < 2464) return 0;
00866     else if (id < 2624) return 1;
00867     else if (id < 2784) return 2;
00868     else if (id < 2944) return 3;
00869 
00870     else if (id < 3136) return 0;
00871     else if (id < 3328) return 1;
00872     else if (id < 3520) return 2;
00873     else if (id < 3712) return 3;
00874     else if (id < 3904) return 4;
00875 
00876     else if (id < 4112) return 0;
00877     else if (id < 4320) return 1;
00878     else if (id < 4528) return 2;
00879     else if (id < 4736) return 3;
00880 
00881     else if (id < 4976) return 0;
00882     else if (id < 5216) return 1;
00883     else if (id < 5456) return 2;
00884     else if (id < 5696) return 3;
00885     else if (id < 5936) return 4;
00886 
00887     else if (id < 6192) return 0;
00888     else if (id < 6448) return 1;
00889     else if (id < 6704) return 2;
00890     else if (id < 6960) return 3;
00891 
00892     else if (id < 7248) return 0;
00893     else if (id < 7536) return 1;
00894     else if (id < 7824) return 2;
00895     else if (id < 8112) return 3;
00896     else if (id < 8400) return 4;
00897 
00898     return 9999;    
00899 */
00900 }
00901 
00902 unsigned
00903 TMDC::localLayerId(const MdcGeoWire * const w) {
00904     if (! w) return 9999;
00905     return w->Layer()%4;
00906     
00907 //    unsigned id = w->Id();
00908 //    return localLayerId(id);
00909 }
00910 
00911 //unsigned
00912 //TMDC::localLayerId(const Geocdc_wire * const w) {
00913 //    if (! w) return 9999;
00914 //    unsigned id = w->get_ID() - 1;
00915 //    return localLayerId(id);
00916 //}
00917 
00918 unsigned
00919 TMDC::localLayerId(const MdcGeoLayer * const l) {
00920     if (! l) return 9999;
00921     unsigned id = l->Id();
00922     if (id < 44) return id%4;      
00923     return 9999;
00924     
00925 /*    if (id < 1) return 0;
00926     else if (id < 2) return 1;
00927     else if (id < 3) return 2;
00928     else if (id < 4) return 3;
00929     else if (id < 5) return 4;
00930     else if (id < 6) return 5;
00931 
00932     else if (id < 7) return 0;
00933     else if (id < 8) return 1;
00934     else if (id < 9) return 2;
00935 
00936     else if (id < 10) return 0;
00937     else if (id < 11) return 1;
00938     else if (id < 12) return 2;
00939     else if (id < 13) return 3;
00940     else if (id < 14) return 4;
00941     else if (id < 15) return 5;
00942 
00943     else if (id < 16) return 0;
00944     else if (id < 17) return 1;
00945     else if (id < 18) return 2;
00946 
00947     else if (id < 19) return 0;
00948     else if (id < 20) return 1;
00949     else if (id < 21) return 2;
00950     else if (id < 22) return 3;
00951     else if (id < 23) return 4;
00952 
00953     else if (id < 24) return 0;
00954     else if (id < 25) return 1;
00955     else if (id < 26) return 2;
00956     else if (id < 27) return 3;
00957 
00958     else if (id < 28) return 0;
00959     else if (id < 29) return 1;
00960     else if (id < 30) return 2;
00961     else if (id < 31) return 3;
00962     else if (id < 32) return 4;
00963 
00964     else if (id < 33) return 0;
00965     else if (id < 34) return 1;
00966     else if (id < 35) return 2;
00967     else if (id < 36) return 3;
00968 
00969     else if (id < 37) return 0;
00970     else if (id < 38) return 1;
00971     else if (id < 39) return 2;
00972     else if (id < 40) return 3;
00973     else if (id < 41) return 4;
00974 
00975     else if (id < 42) return 0;
00976     else if (id < 43) return 1;
00977     else if (id < 44) return 2;
00978     else if (id < 45) return 3;
00979 
00980     else if (id < 46) return 0;
00981     else if (id < 47) return 1;
00982     else if (id < 48) return 2;
00983     else if (id < 49) return 3;
00984     else if (id < 50) return 4;
00985 
00986     return 9999;    
00987 */
00988 }
00989 
00990 unsigned
00991 TMDC::axialStereoLayerId(const MdcGeoLayer * const l) {
00992     if (! l) return 9999;
00993     unsigned id = l->Id();
00994 
00995     if (id < 8) return id;
00996     else if (id < 20) return id-8;
00997     else if (id < 36) return id-12;
00998     else if (id < 43) return id-24;
00999 
01000     return 9999;    
01001 }
01002 
01003 unsigned
01004 TMDC::layerId(unsigned as, unsigned id) {
01005 
01006     //...Axial case...
01007     if (as == 0) {
01008         if (id < 12) return id + 8;
01009         else if (id < 19) return id + 24;
01010         return 9999;
01011     }
01012 
01013     //...Stereo case...
01014     if (id < 8) return id;
01015     else if (id < 24) return id + 12;
01016     return 9999;
01017 }
01018 
01019 std::string
01020 TMDC::wireName(const MdcRec_wirhit & h) {
01021 //    geocdc_wire * g = (geocdc_wire *) BsGetEnt(GEOMDC_WIRE,
01022 //                                             h.m_geo,
01023 //                                             BBS_No_Index);
01024       const MdcGeoWire* g = h.geo;
01025       return wireName(g);
01026 }
01027 
01028 void
01029 TMDC::driftDistance(TMLink & l,
01030                     const TTrack & t,
01031                     unsigned flag,
01032                     float t0Offset) {
01033 
01034     //...No correction...
01035     if (flag == 0) {
01036         if (l.hit()) {
01037             l.drift(0, l.hit()->drift(0));
01038             l.drift(1, l.hit()->drift(1));
01039             l.dDrift(0, l.hit()->dDrift(0));
01040             l.dDrift(1, l.hit()->dDrift(1));
01041         }
01042         else {
01043             l.drift(0, 0.);
01044             l.drift(1, 0.);
01045             l.dDrift(0, 0.);
01046             l.dDrift(1, 0.);
01047         }
01048 
01049         return;
01050     }
01051 
01052     //...TOF correction...
01053     float tof = 0.;
01054     if (flag && 1) {
01055         int imass = 3;
01056         float tl = t.helix().a()[4];
01057         float f = sqrt(1. + tl * tl);
01058         float s = fabs(t.helix().curv()) * fabs(l.dPhi()) * f;
01059         float p = f / fabs(t.helix().a()[2]);
01060 //zsl   calcdc_tof2_(& imass, & p, & s, & tof); 
01061     }
01062 
01063     //...T0 correction....
01064     if (! (flag && 2)) t0Offset = 0.;
01065 
01066     //...Propagation corrections...
01067     const TMDCWireHit & h = * l.hit();
01068     int wire = h.wire()->id();
01069     HepVector3D tp = t.helix().momentum(l.dPhi());
01070     float p[3] = {tp.x(), tp.y(), tp.z()};
01071     const HepPoint3D & onWire = l.positionOnWire();
01072     float x[3] = {onWire.x(), onWire.y(), onWire.z()};
01073     float time = h.reccdc()->tdc + t0Offset - tof;
01074     float dist;
01075     float edist;
01076     int prop = (flag & 4);
01077 
01078     //...Calculation with left side...
01079     int side = -1;
01080     if (side == 0) side = -1;
01081 //zsl    calcdc_driftdist_(& prop,
01082 //                    & wire,
01083 //                    & side,
01084 //                    p,
01085 //                    x,
01086 //                    & time,
01087 //                    & dist,
01088 //                    & edist);
01089     l.drift(0, dist);
01090     l.dDrift(0, edist);
01091 
01092     //...Calculation with left side...
01093     side = 1;
01094 //zsl    calcdc_driftdist_(& prop,
01095 //                    & wire,
01096 //                    & side,
01097 //                    p,
01098 //                    x,
01099 //                    & time,
01100 //                    & dist,
01101 //                    & edist);
01102     l.drift(1, dist);
01103     l.dDrift(1, edist);
01104 
01105     //...tan(lambda) correction...
01106     if (flag && 8) {
01107         float tanl = abs(p[2]) / tp.perp();
01108         float c;
01109         if ((tanl >= 0.0) && (tanl < 0.5))      c = -0.48 * tanl + 1.3;
01110         else if ((tanl >= 0.5) && (tanl < 1.0)) c = -0.28 * tanl + 1.2;
01111         else if ((tanl >= 1.0) && (tanl < 1.5)) c = -0.16 * tanl + 1.08;
01112         else                                    c =  0.84;
01113 
01114         l.dDrift(0, l.dDrift(0) * c);
01115         l.dDrift(1, l.dDrift(1) * c);
01116     }
01117 }

Generated on Tue Nov 29 23:14:15 2016 for BOSS_7.0.2 by  doxygen 1.4.7