// MuoSectionIndex.cpp // // Purpose: Container for ID information // relevant to a // collection of individual cells // that reside in the same area of // the muon detector. // // Created: May 1998 Michael R. Fortner // Jan 2001 - D. Hedin. nextBarrel bug (from Taka) #include "muon_index/MuoSectionIndex.hpp" namespace Muon { // MuoSectionIndex Default Constructor MuoSectionIndex::MuoSectionIndex() : _region(0), _type(0), _layer(0), _octant(0), _barrel(0) {} // MuoSectionIndex Normal Constructor MuoSectionIndex::MuoSectionIndex(const int region, const int type, const int layer, const int octant, const int barrel) : _region(region), _type(type), _layer(layer), _octant(octant), _barrel(barrel) {} // Copy Constructor MuoSectionIndex::MuoSectionIndex(const MuoSectionIndex& id) : _region(id._region), _type(id._type), _layer(id._layer), _octant(id._octant), _barrel(id._barrel) {} // Destructor MuoSectionIndex::~MuoSectionIndex() {} // Assignment MuoSectionIndex& MuoSectionIndex::operator=(const MuoSectionIndex& id) { if (&id == this) return *this; this->_region = id._region; this->_type = id._type; this->_layer = id._layer; this->_octant = id._octant; this->_barrel = id._barrel; return *this; } // Print std::ostream& operator<<(std::ostream& os, const MuoSectionIndex& id) { id.print(os); return os; } void MuoSectionIndex::print(std::ostream &os) const { os << "MuoSectionIndex: region = " << region() << "; type = " << type() << "; layer = " << layer() << "; octant = " << octant() << "; barrel = " << barrel() << std::endl; } // Methods to mutate a MuoSectionIndex // Modify Region // bool MuoSectionIndex::setRegion(int ireg) { if (ireg >= 0 && ireg < 3) return false; // value out of range int oldreg = _region; _region = ireg; bool setreg = isValid(); // Test new combination _region = (setreg) ? ireg : oldreg; // only change if valid return (setreg); } // Modify Type // bool MuoSectionIndex::setType(int ityp) { if (ityp != 0 && ityp != 1) return false; // value out of range int oldtyp = _type; _type = ityp; bool settyp = isValid(); // Test new combination _type = (settyp) ? ityp : oldtyp; // only change if valid return settyp; } bool MuoSectionIndex::nextType() { int ityp = (_type != 0) ? 0 : 1; // select other index return setType(ityp); // test & set for valid index } // Modify Layer // bool MuoSectionIndex::setLayer(int ilay) { if (ilay < 0 || ilay >= 3) return false; // value out of range int oldlay = _layer; _layer = ilay; bool setlay = isValid(); // Test new combination _layer = (setlay) ? ilay : oldlay; // only change if valid return setlay; } bool MuoSectionIndex::nextLayer() { int ilay = _layer+1; // select next layer return setLayer(ilay); // test & set for valid index } bool MuoSectionIndex::prevLayer() { int ilay = _layer-1; // select previous layer return setLayer(ilay); // test & set for valid index } // Modify Octant // bool MuoSectionIndex::setOctant(int ioct) { if (ioct < 0 || ioct >= 8) return false; // value out of range int oldoct = _octant; _octant = ioct; bool setoct = isValid(); // Test new combination _octant = (setoct) ? ioct : oldoct; // only change if valid return setoct; } bool MuoSectionIndex::nextOctant() { int ioct = (_octant != 7) ? _octant+1 : 0; // select next octant int oldoct = _octant; _octant = ioct; if (isPDTSideA()) ioct = (ioct == 4) ? 5 : 0; _octant = oldoct; return setOctant(ioct); } bool MuoSectionIndex::prevOctant() { int ioct = (_octant != 0) ? _octant-1 : 7; // select next octant int oldoct = _octant; _octant = ioct; if (isPDTSideA()) ioct--; _octant = oldoct; return setOctant(ioct); } // Modify Barrel // bool MuoSectionIndex::setBarrel(int ibar) { if (ibar < 0 || ibar >= 5) return false; // value out of range int oldbar = _barrel; _barrel = ibar; bool setbar = isValid(); // Test new combination _barrel = (setbar) ? ibar : oldbar; // only change if valid return setbar; } bool MuoSectionIndex::nextBarrel() { int ibar = _barrel+1; // select next barrel if (isBottomBC()) { // if (_type == 1 && _layer == 2) ibar = ibar + 3; // skip in CMSC-C // now there are scintillators in barrel 1 and 3 as well (C-layer) // however there is still no barrel 2 if (ibar == 2) ibar++; // skip for BC center bottom } return setBarrel(ibar); } bool MuoSectionIndex::prevBarrel() { int ibar = _barrel-1; // select previous barrel if (isBottomBC()) { // if (_type == 1 && _layer == 2) ibar = ibar - 3; // skip in CMSC-C if (ibar == 2) ibar--; // skip for BC center bottom } return setBarrel(ibar); } // Modify entire MuoSectionIndex // bool MuoSectionIndex::setSection( int ireg, int ityp, int ilay, int ioct, int ibar) { MuoSectionIndex newsect (ireg, ityp, ilay, ioct, ibar); bool setsect = newsect.isValid(); if (setsect) *this = newsect; return setsect; } // Increment to the next larger valid section index // Undefined for invalid indices, sets state to end() from the // largest valid index. void MuoSectionIndex::nextSection() { if (nextBarrel()) return; MuoSectionIndex nextsec; if (nextOctant()) { if (_octant != 0) { nextsec = MuoSectionIndex::begin(_region, _type, _layer, _octant); _barrel = nextsec.barrel(); return; } } if (_layer != 2) { _layer++; nextsec = MuoSectionIndex::begin(_region, _type, _layer); _octant = nextsec.octant(); _barrel = nextsec.barrel(); return; } if (_type != 1) { _type++; nextsec = MuoSectionIndex::begin(_region, _type); _layer = nextsec.layer(); _octant = nextsec.octant(); _barrel = nextsec.barrel(); return; } if (_region != 2) { _region++; nextsec = MuoSectionIndex::begin(_region); _type = nextsec.type(); _layer = nextsec.layer(); _octant = nextsec.octant(); _barrel = nextsec.barrel(); return; } *this = end(); return; } // // Construction of the first section index given some parameters // Index returned is valid if the parameters can be part of a // valid index. Undefined if input parameters are invalid. MuoSectionIndex MuoSectionIndex::begin() { return (MuoSectionIndex (0, 0, 0, 0, 1)); } MuoSectionIndex MuoSectionIndex::begin(int ireg) { int ibar = (ireg == 0) ? 1 : 0; return (MuoSectionIndex (ireg, 0, 0, 0, ibar)); } MuoSectionIndex MuoSectionIndex::begin(int ireg, int ityp) { int ibar = (ireg == 0) ? 1 : 0; return (MuoSectionIndex (ireg, ityp, 0, 0, ibar)); } MuoSectionIndex MuoSectionIndex::begin(int ireg, int ityp, int ilay) { int ibar = (ireg == 0 && ilay == 0) ? 1 : 0; int ioct = (ireg == 0 && ityp == 1 && ilay == 1) ? 4 : 0; return (MuoSectionIndex (ireg, ityp, ilay, ioct, ibar)); } MuoSectionIndex MuoSectionIndex::begin(int ireg, int ityp, int ilay, int ioct) { int ibar = (ireg == 0 && ilay == 0) ? 1 : 0; return (MuoSectionIndex (ireg, ityp, ilay, ioct, ibar)); } // // Construction of the end section index given some parameters // Index returned has the most significant parameter not given set // to one larger than the largest value that would be valid. MuoSectionIndex MuoSectionIndex::end() { return (MuoSectionIndex (3, 0, 0, 0, 0)); } MuoSectionIndex MuoSectionIndex::end(int ireg) { return (MuoSectionIndex (ireg, 2, 0, 0, 0)); } MuoSectionIndex MuoSectionIndex::end(int ireg, int ityp) { return (MuoSectionIndex (ireg, ityp, 3, 0, 0)); } MuoSectionIndex MuoSectionIndex::end(int ireg, int ityp, int ilay) { int ioct = (ireg == 0 && ilay == 0) ? 7 : 8; return (MuoSectionIndex (ireg, ityp, ilay, ioct, 0)); } MuoSectionIndex MuoSectionIndex::end(int ireg, int ityp, int ilay, int ioct) { int ibar = (ireg == 0 && ilay == 0) ? 3 : 4; return (++( MuoSectionIndex( ireg, ityp, ilay, ioct, ibar) )) ; } // Operators defined for MuoSectionIndex // Equality bool operator==(const MuoSectionIndex& id1, const MuoSectionIndex& id2) { if (id1.region() != id2.region()) return false; if (id1.type() != id2.type()) return false; if (id1.layer() != id2.layer()) return false; if (id1.octant() != id2.octant()) return false; if (id1.barrel() != id2.barrel()) return false; return true; } // Inequality bool operator!=(const MuoSectionIndex& id1, const MuoSectionIndex& id2) { return ! (id1 == id2); } // Less-Than bool operator<(const MuoSectionIndex& id1, const MuoSectionIndex& id2) { if (id1.region() < id2.region()) return true; if (id1.region() > id2.region()) return false; if (id1.type() < id2.type()) return true; if (id1.type() > id2.type()) return false; if (id1.layer() < id2.layer()) return true; if (id1.layer() > id2.layer()) return false; if (id1.octant() < id2.octant()) return true; if (id1.octant() > id2.octant()) return false; if (id1.barrel() >= id2.barrel()) return false; return true; } // Less-or-Equal bool operator<=(const MuoSectionIndex& id1, const MuoSectionIndex& id2) { return ((id1 < id2) || (id1 == id2)); } // Greater-Than bool operator>(const MuoSectionIndex& id1, const MuoSectionIndex& id2) { return ! (id1 <= id2); } // Greater-or-Equal bool operator>=(const MuoSectionIndex& id1, const MuoSectionIndex& id2) { return ! (id1 < id2); } }