#ifdef USE_CDFEDM2 ////////////////////////////////////////////////////////////////////////// // // Component: TdcTower.cc // Purpose: Implementation of TdcTower class // // Created: 01/22/2003 Max Goncharov // ////////////////////////////////////////////////////////////////////////// #include #include #include "CalorObjects/TdcTower.hh" #include using namespace std; // // Memory management // TdcHit::TdcHit(int hit, int width): _t0(hit),_wt0(width), _valid(0),_corrected(false), _wedge(-1),_tower(-1), _ewe(-1),_calor(ERRCAL) { checkT0(); checkWidth(); } TdcHit::~TdcHit() {} void TdcHit::set_geometry(int wedge,int tower, int ewe, Detector c){ _wedge = wedge; _tower = tower; _ewe = ewe; _calor = c; } void TdcHit::get_geometry(int& wedge,int& tower, int& ewe, Detector& c) const{ wedge = _wedge; tower = _tower; ewe = _ewe; c = _calor; } void TdcHit::set_hit(float time, float width){ _t0 = time; checkT0(); _wt0 = width; checkWidth(); } void TdcHit::get_hit(float& time, float& width) const{ time = _t0; width = _wt0; } void TdcHit::checkT0(){ if(_t0 < _tMin || _t0 > _tMax) _valid = _valid & 1; } void TdcHit::checkWidth(){ if(_wt0 < _wMin || _wt0 > _wMax) _valid = _valid & 2; } void TdcHit::reset(){ _valid = 0; _t0 = 0.; _wt0 = 0.; } int TdcHit::PrintValidCode() const { int word = 0; int place= 1; valcode_t iWord = this->validCode(); for(int i= 0;i<8;i++) { int bit = 0; bit = (iWord >> i) & ~(~0 << 1) ; word = word + place*bit; place = place*10; } return word; } void TdcHit::print(std::ostream& os) const{ os<< *this; } bool TdcHit::operator==(const TdcHit& rhs) const { if (this == &rhs) return true; return (_t0 == rhs._t0 && _wt0 == rhs._wt0); } bool TdcHit::operator>(const TdcHit& rhs) const { if (this == &rhs) return false; if(_t0 > rhs._t0) return true; else return false; } bool TdcHit::operator<(const TdcHit& rhs) const { if (this == &rhs) return false; if(_t0 < rhs._t0) return true; else return false; } ostream& operator<<(std::ostream& os, const TdcHit& t) { float time, width; t.get_hit(time,width); os << '\n'; os << "Time: "<< time <<" "; os << "Width: " << width << " "; os << "validcode: " << setfill('0') < (& jt->first); CalorKeyMap::const_iterator it = rhs._calor_keys.begin(); bool found = false; while(it != rhs._calor_keys.end()){ const CalorKey* key2 = & (it->first); if( (*key1) == (*key2)){ found = true; break; } it++; } if(! found) return false; jt++; } return true; } bool TdcTower::operator < (const TdcTower& rhs) const{ if (this == &rhs) return false; if (_calor_keys < rhs.getCalorKeys()) return true; return false; } bool TdcTower::operator > (const TdcTower& rhs) const{ if (this == &rhs) return false; if (_calor_keys > rhs.getCalorKeys()) return true; return false; } TdcHit TdcTower::accessHit(int ihit) const{ if(ihit > CAL_TDC_NHITS - 1) ihit = CAL_TDC_NHITS - 1; if(ihit < 0) ihit = 0; return _tdc_hits[ihit]; } bool TdcTower::hasCalorKey(const CalorKey& ckey) const{ CalorKeyMap::const_iterator it = _calor_keys.find(ckey); if(it == _calor_keys.end()) return false; else return true; } float TdcTower::getPmtEnergy(int j) const{ if(! (j < _calor_keys.size()) ) return 0.; CalorKeyMap::const_iterator it = _calor_keys.begin(); int i = 0; while(it != _calor_keys.end()){ if(i == j) break; i++; it++; } return it->second; } float TdcTower::getPmtEnergy(const CalorKey& ckey) const{ CalorKeyMap::const_iterator it = _calor_keys.find(ckey); if(it == _calor_keys.end()) return -999.; else return it->second; } bool TdcTower::addTdcHit(int t0, int wt0){ TdcHit thehit(t0,wt0); return addTdcHit(thehit); } bool TdcTower::addTdcHit(const TdcHit& hit){ if(hit.validCode()) return false; if(! (_nTdcHits < CAL_TDC_NHITS) ) return false; _tdc_hits[_nTdcHits] = hit; _nTdcHits++; return true; } bool TdcTower::addEnergy(const CalorKey& key, float pmtE){ CalorKeyMap::iterator it = _calor_keys.find(key); if(it == _calor_keys.end()){ _calor_keys[key] = pmtE; _nCalorKeys++; return true; }else return false; } bool TdcTower::setEnergy(const CalorKey& key, float pmtE){ CalorKeyMap::iterator it = _calor_keys.find(key); if(it != _calor_keys.end()){ _calor_keys[key] = pmtE; return true; }else return false; } void TdcTower::reset(){ _nTdcHits = 0; _nCalorKeys = 0; _valid = 0; memset(_tdc_hits,0,sizeof(int)*CAL_TDC_NHITS); _calor_keys.clear(); } bool TdcTower::setCalorKeys(const CalorKeyMap& themap){ _calor_keys = themap; _nCalorKeys = _calor_keys.size(); return true; } int TdcTower::PrintValidCode() const { int word = 0; int place= 1; valcode_t iWord = this->validCode(); for(int i= 0;i<8;i++) { int bit = 0; bit = (iWord >> i) & ~(~0 << 1) ; word = word + place*bit; place = place*10; } return word; } ostream& operator<<(std::ostream& os, const TdcTower& t) { return t.print(os); } std::ostream& TdcTower::print(std::ostream& os) const{ os << '\n'; os << "N Hits: "<< howManyHits() <<" "; for(int i = 0; i < howManyHits(); i ++){ os<second<<"\n"; } os << "validcode: " << setfill('0') <