//*********************************************************************** // File: TdcKey.cc // ---------------------------------------------------------------------- // Class implementation source. // // Author List: // Igor Gorelov // University of New Mexico // June 05, 01 // Revisions: // // added additional methods to unfold software indexes // back to hardware ones. (Igor Gorelov, 9-Jul-01) //======================================================================== // //************************************************************************ //============================================================================= // Declarations and Definitions //============================================================================= #include #include #include "CalorObjects/TdcKey.hh" #include "CalorGeometry/CalConstants.hh" static const std::string detectorName[] = { "CEM", "PEM", "CHA", "WHA", "PHA", "STRIP", "CRACK", "PPR", "MPA", "DEFAULT", "ERRCAL" }; //============================================================================= // Constructors: //============================================================================= TdcKey::TdcKey(): _ixEta(0), _ixPhi(0), _calodet(ERRCAL), _validFlag(false){ } TdcKey::TdcKey( int side, int wedge, int rapidity, int depth_or_tile){ setTdcIdx(side, wedge, rapidity, depth_or_tile); return; } TdcKey::TdcKey( int eta, int phi, Detector subdet ) { _ixEta = eta; _ixPhi = phi; _calodet = subdet; if (eta > TOWER_NETA-1 || eta <0 || phi > TOWER_MAX_NPHI-1 || phi <0) { _ixEta = 0; _ixPhi = 0; _calodet = ERRCAL; _validFlag = false; return; } _validFlag = false; int towtyp = TOWER_TYPE[eta]; if ( (towtyp >4&&towtyp <8) && subdet==PHA ) {_validFlag = true;} if ( (towtyp >1&&towtyp <5) && subdet==WHA ) {_validFlag = true;} if ( (towtyp==1) && (subdet==CHA||subdet==WHA) ) {_validFlag = true;} if ( (towtyp==0) && (subdet==CHA) ) {_validFlag = true;} if ( phi > TOWER_PHI_SEG[towtyp]-1 ) {_validFlag = false;} return; } TdcKey::TdcKey( const TdcKey &tkey ) { _ixEta = tkey._ixEta; _ixPhi = tkey._ixPhi; _calodet = tkey._calodet; _validFlag = tkey._validFlag; } TdcKey::TdcKey( const TdcKey* tkey ) { _ixEta = tkey->_ixEta; _ixPhi = tkey->_ixPhi; _calodet = tkey->_calodet; _validFlag = tkey->_validFlag; } TdcKey::~TdcKey() { } //============================================================================= // Set key values and partial values; //============================================================================= int TdcKey::setTdcIdx( int side, int wedge, int rapidity, int depth_or_tile){ // TDC bank - check hardware channel/module ID ... _validFlag = false; // east , west if ( (side <0) || (side >1) ) { _ixEta = 0; _ixPhi = 0; _calodet = ERRCAL; return -1; } // the raw wedge number runs from 0 till 23 including PHA if ( (wedge <0 )||(wedge >TENPHI/2 -1) ) { _ixEta = 0; _ixPhi = 0; _calodet = ERRCAL; return -1; } // raw tower numbers - 0 ... 21 if ( (rapidity <0) || (rapidity >21) ) { _ixEta = 0; _ixPhi = 0; _calodet = ERRCAL; return -1; } // following the description of HATD_StorableBank ... if ( (rapidity <= 5 && depth_or_tile == 1) || (rapidity >= 8 && rapidity <= 11 && depth_or_tile == 0) || (rapidity > 21) || (rapidity >= 18 && depth_or_tile == 1) ) { _ixEta = 0; _ixPhi = 0; _calodet = ERRCAL; return -1; } // when raw indexes look O.K. - find the subdetector and determine // software indexes ... _validFlag = true; _ixEta = TENETA/2 - 1 - rapidity; if (side ==1) _ixEta = TENETA/2 + rapidity; _ixPhi = wedge; // tower type 0 and 1 - CHA if "Bit 0" or "depth_or_tile" = 0 ... if( (TETTYP[_ixEta] ==0) || ((TETTYP[_ixEta] ==1)&&(depth_or_tile ==0)) ) { _calodet = CHA; } // tower type 1,2,3,4 - WHA if "Bit 0" or "depth_or_tile" = 1 ... // tower type 4 (eta=11) has WHA and PHA but // only WHA instrumented with TDC (so E. James) if( ( (TETTYP[_ixEta] >0)&&(TETTYP[_ixEta] <5) )&&(depth_or_tile ==1) ) { _calodet = WHA; } // tower type 5 - PHA with phi granuarity of 48 ... if( TETTYP[_ixEta] ==5 ) { // "Bit 0" or "depth_or_tile" = 0 for low phi tile, = 1 for high phi tile ... _ixPhi = 2*wedge +depth_or_tile; _calodet = PHA; } // tower type 6,7 - PHA with phi granuarity of 24 ... if( ( (TETTYP[_ixEta] >5)&&(TETTYP[_ixEta] <8) )&&(depth_or_tile ==0) ) { _calodet = PHA; } return 1; } std::string TdcKey::calodetName(void) const { if (_calodet >= ERRCAL) return "ERRCAL"; return detectorName[_calodet]; } int TdcKey::iside() const { if (_ixEta < TENETA/2) { return 0;} else { return 1; } } int TdcKey::iwedge() const { switch(_calodet) { case CHA: case WHA: return _ixPhi; case PHA: if( TETTYP[_ixEta] ==5 ) { return (_ixPhi/2); } else { return _ixPhi; } default: return _ixPhi; } } int TdcKey::idepth() const { switch(_calodet) { case CHA: return 0; case WHA: return 1; case PHA: if( TETTYP[_ixEta] ==5 ) { return (_ixPhi%2); } else { return 0; } default: return 0; } } int TdcKey::irap() const { if (_ixEta < TENETA/2) { return (TENETA/2 - 1 -_ixEta); } else { return (_ixEta -TENETA/2); } } //============================================================================= // Print routine: //============================================================================= void TdcKey::print(void) const { std::cout << std::endl; std::cout << "----------------------------------------------------" << std::endl; std::cout << " TdcKey - subDetector " << calodetName(); if (isValid()) std::cout << " is valid " << std::endl; else std::cout << " is not valid " << std::endl; std::cout << " Software Indexes : " << std::endl; std::cout << " ixEta " << _ixEta << std::endl; std::cout << " ixPhi " << _ixPhi << std::endl; std::cout << " Hardware Indexes : " << std::endl; std::cout << " side/rap/wedge/depth " << iside() << " / " << irap() << " / " << iwedge() << " / " << idepth() << " / " << std::endl; std::cout << "----------------------------------------------------" << std::endl; return; } //***************************************************************************** // The End //*****************************************************************************